NDArrayAdvanced#

class numpy::NDArrayAdvanced#

numpy C++ class.

Example#

#include <numpy/np_ndarray.h>
using namespace numpy;

// Use NDArrayAdvanced
NDArrayAdvanced obj;
// ... operations ...

Constructors#

Signature

Location

Example

NDArrayAdvanced(const NDArray<T>&array)

NP_NDARRAY_ADVANCED.H:23

NDArrayAdvanced(NDArray<T>&&array)

NP_NDARRAY_ADVANCED.H:24

Operators#

Signature

Return Type

Location

Example

T operator[](ssize_tindex)

T

NP_NDARRAY_ADVANCED.H:32

IndexedArrayResult<T> operator[](const IndexExpr &expr)

IndexedArrayResult<T>

NP_NDARRAY_ADVANCED.H:45

IndexedArrayResult<T> operator[](const IndexExpr &expr)

IndexedArrayResult<T>

NP_NDARRAY_ADVANCED.H:49

IndexedArrayResult<T> operator[](const Slice &slice)

IndexedArrayResult<T>

NP_NDARRAY_ADVANCED.H:54

NDArray<T> operator[](const NDArray<bool\_>&mask)

NDArray<T>

NP_NDARRAY_ADVANCED.H:61

NDArray<T> operator[](const NDArray<size_t>&indices)

NDArray<T>

NP_NDARRAY_ADVANCED.H:66

NDArray<T> operator[](const NDArray<int32_t>&indices)

NDArray<T>

NP_NDARRAY_ADVANCED.H:77

Indexing / Selection#

Signature

Return Type

Location

Example

auto getitem(Args...args)

auto

NP_NDARRAY_ADVANCED.H:95

void put(const NDArray<size_t>&indices, const NDArray<T>&values)

void

NP_NDARRAY_ADVANCED.H:133

View

Math Operations#

Signature

Return Type

Location

Example

void add_to_expr(IndexExpr &expr, ssize_tidx)

void

NP_NDARRAY_ADVANCED.H:187

void add_to_expr(IndexExpr &expr, const Slice &slice)

void

NP_NDARRAY_ADVANCED.H:191

void add_to_expr(IndexExpr &expr, const NDArray<size_t>&array)

void

NP_NDARRAY_ADVANCED.H:195

void add_to_expr(IndexExpr &expr, const NDArray<bool\_>&array)

void

NP_NDARRAY_ADVANCED.H:199

void add_to_expr(IndexExpr &expr, const Ellipsis &e)

void

NP_NDARRAY_ADVANCED.H:203

void add_to_expr(IndexExpr &expr, const NewAxis &n)

void

NP_NDARRAY_ADVANCED.H:207

void add_to_expr(IndexExpr &expr, const Colon &c)

void

NP_NDARRAY_ADVANCED.H:211

Other Methods#

Signature

Return Type

Location

Example

void assign_values(NDArray<T>&target, const NDArray<T>&source)

void

NP_NDARRAY_ADVANCED.H:216

void build_index_expr(IndexExpr &expr, Firstfirst, Rest...rest)

void

NP_NDARRAY_ADVANCED.H:179

void setitem(const NDArray<T>&values, Args...args)

void

NP_NDARRAY_ADVANCED.H:103

Code Examples#

The following examples are extracted from the test suite.

put (np_test_5_all.cpp:4389)
4379      numpy::NDArray<size_t> indices({ 3 });
4380      indices.setElementAt({ 0 }, 5);  // Last position
4381      indices.setElementAt({ 1 }, 2);  // Middle position
4382      indices.setElementAt({ 2 }, 0);  // First position
4383
4384      numpy::NDArray<int32_t> values({ 3 });
4385      values.setElementAt({ 0 }, 100);
4386      values.setElementAt({ 1 }, 200);
4387      values.setElementAt({ 2 }, 300);
4388
4389      numpy::put(arr, indices, values);
4390
4391      // Check modified values
4392      if (arr.getElementAt({ 0 }) != 300 || arr.getElementAt({ 2 }) != 200 || arr.getElementAt({ 5 }) != 100) {
4393        std::cout << "  [FAIL] : in np_test_put_basic() : Values not correctly placed";
4394        throw std::runtime_error("Test failed");
4395      }
4396
4397      // Check unmodified values
4398      if (arr.getElementAt({ 1 }) != 10 || arr.getElementAt({ 3 }) != 30 || arr.getElementAt({ 4 }) != 40) {
4399        std::cout << "  [FAIL] : in np_test_put_basic() : Unmodified values changed";