The N-Dimensional array (cunumeric.ndarray)#

Constructing arrays#

New arrays can be constructed using the routines detailed in Array creation routines, and also by using the low-level ndarray constructor:

ndarray()

Calculation#

ndarray.all([axis, out, keepdims, initial, ...])

Returns True if all elements evaluate to True.

ndarray.any([axis, out, keepdims, initial, ...])

Returns True if any of the elements of a evaluate to True.

Array Attributes#

Memory Layout#

ndarray.flags

Information about the memory layout of the array.

ndarray.shape

Tuple of array dimensions.

ndarray.strides

Tuple of bytes to step in each dimension when traversing an array.

ndarray.ndim

Number of array dimensions.

ndarray.data

Python buffer object pointing to the start of the array's data.

ndarray.size

Number of elements in the array.

ndarray.itemsize

The element size of this data-type object.

ndarray.nbytes

Total bytes consumed by the elements of the array.

ndarray.base

Returns dtype for the base element of the subarrays, regardless of their dimension or shape.

ndarray.ctypes

An object to simplify the interaction of the array with the ctypes module.

Data Type#

ndarray.dtype

Data-type of the array's elements.

Other Attributes#

ndarray.T

The transposed array.

ndarray.real

The real part of the array.

ndarray.imag

The imaginary part of the array.

ndarray.flat

A 1-D iterator over the array.

Array Methods#

Array conversion#

ndarray.item(*args)

Copy an element of an array to a standard Python scalar and return it.

ndarray.tolist()

Return the array as an a.ndim-levels deep nested list of Python scalars.

ndarray.itemset

ndarray.tostring([order])

A compatibility alias for tobytes, with exactly the same behavior.

ndarray.tobytes([order])

Construct Python bytes containing the raw data bytes in the array.

ndarray.tofile(fid[, sep, format])

Write array to a file as text or binary (default).

ndarray.dump(file)

Dump a pickle of the array to the specified file.

ndarray.dumps()

Returns the pickle of the array as a string.

ndarray.astype(dtype[, order, casting, ...])

Copy of the array, cast to a specified type.

ndarray.copy()

Get a copy of the iterator as a 1-D array.

ndarray.view([dtype, type])

New view of array with the same data.

ndarray.getfield(dtype[, offset])

ndarray.setfield(val, dtype[, offset])

ndarray.setflags([write, align, uic])

Set array flags WRITEABLE, ALIGNED, WRITEBACKIFCOPY, respectively.

ndarray.fill(value)

Fill the array with a scalar value.

Shape manipulation#

ndarray.reshape(shape[, order])

Returns an array containing the same data with a new shape.

ndarray.transpose([axes])

Returns a view of the array with axes transposed.

ndarray.swapaxes(axis1, axis2)

Return a view of the array with axis1 and axis2 interchanged.

ndarray.flatten([order])

Return a copy of the array collapsed into one dimension.

ndarray.ravel([order])

Return a flattened array.

ndarray.squeeze([axis])

Remove axes of length one from a.

Item selection and manipulation#

ndarray.take(indices[, axis, out, mode])

Take elements from an array along an axis.

ndarray.put(indices, values[, mode])

Replaces specified elements of the array with given values.

ndarray.choose(choices[, out, mode])

Use an index array to construct a new array from a set of choices.

ndarray.sort([axis, kind, order])

Sort an array in-place.

ndarray.argsort([axis, kind, order])

Returns the indices that would sort this array.

ndarray.partition(kth[, axis, kind, order])

Partition of an array in-place.

ndarray.argpartition(kth[, axis, kind, order])

Returns the indices that would partition this array.

ndarray.searchsorted(v[, side, sorter])

Find the indices into a sorted array a such that, if the corresponding elements in v were inserted before the indices, the order of a would be preserved.

ndarray.nonzero()

Return the indices of the elements that are non-zero.

ndarray.compress(self, condition[, axis, out])

Return selected slices of an array along given axis.

ndarray.diagonal([offset, axis1, axis2])

Return specified diagonals.

ndarray.trace([offset, axis1, axis2, dtype, out])

Return the sum along diagonals of the array.

Calculation#

ndarray.max([axis, out, keepdims, initial, ...])

a.max(axis=None, out=None, keepdims=False, initial=<no value>,

ndarray.argmax([axis, out])

Return indices of the maximum values along the given axis.

ndarray.min([axis, out, keepdims, initial, ...])

a.min(axis=None, out=None, keepdims=False, initial=<no value>,

ndarray.argmin([axis, out])

Return indices of the minimum values along the given axis.

ndarray.clip([min, max, out])

Return an array whose values are limited to [min, max].

ndarray.conj()

Complex-conjugate all elements.

ndarray.conjugate()

Return the complex conjugate, element-wise.

ndarray.dot(rhs[, out])

Return the dot product of this array with rhs.

ndarray.flip([axis])

Reverse the order of elements in an array along the given axis.

ndarray.sum([axis, dtype, out, keepdims, ...])

a.sum(axis=None, dtype=None, out=None, keepdims=False, initial=0, where=None)

ndarray.cumsum([axis, dtype, out])

ndarray.mean([axis, dtype, out, keepdims])

Returns the average of the array elements along given axis.

ndarray.var(a[, axis, dtype, out, ddof, ...])

Returns the variance of the array elements along given axis.

ndarray.prod([axis, dtype, out, keepdims, ...])

a.prod(axis=None, dtype=None, out=None, keepdims=False, initial=1, where=True)

ndarray.cumprod([axis, dtype, out])

ndarray.all([axis, out, keepdims, initial, ...])

Returns True if all elements evaluate to True.

ndarray.any([axis, out, keepdims, initial, ...])

Returns True if any of the elements of a evaluate to True.

ndarray.unique()

Find the unique elements of an array.

Arithmetic, matrix multiplication, and comparison operations#

ndarray.__lt__(value, /)

Return self<value.

ndarray.__le__(value, /)

Return self<=value.

ndarray.__gt__(value, /)

Return self>value.

ndarray.__ge__(value, /)

Return self>=value.

ndarray.__eq__(value, /)

Return self==value.

ndarray.__ne__(value, /)

Return self!=value.

Truth value of an array(bool()):

ndarray.__bool__(/)

Return self!=0

Unary operations:

ndarray.__neg__(value, /)

Return -self.

ndarray.__pos__(value, /)

Return +self.

ndarray.__abs__(/)

Return abs(self).

ndarray.__invert__(/)

Return ~self.

Arithmetic:

ndarray.__add__(value, /)

Return self+value.

ndarray.__sub__(value, /)

Return self-value.

ndarray.__mul__(value, /)

Return self*value.

ndarray.__truediv__(value, /)

Return self/value.

ndarray.__floordiv__(value, /)

Return self//value.

ndarray.__mod__(value, /)

Return self%value.

ndarray.__divmod__(value, /)

Return divmod(self, value).

ndarray.__pow__(value, /)

Return pow(self, value).

ndarray.__lshift__(value, /)

Return self<<value.

ndarray.__rshift__(value, /)

Return self>>value.

ndarray.__and__(value, /)

Return self&value.

ndarray.__or__(value, /)

Return self|value.

ndarray.__xor__(value, /)

Return self^value.

Arithmetic, in-place:

ndarray.__iadd__(value, /)

Return self+=value.

ndarray.__isub__(/)

Return self-=value.

ndarray.__imul__(value, /)

Return self*=value.

ndarray.__itruediv__(/)

Return self/=value.

ndarray.__ifloordiv__(value, /)

Return self//=value.

ndarray.__imod__(value, /)

Return self%=value.

ndarray.__ipow__(/)

Return self**=value.

ndarray.__ilshift__(value, /)

Return self<<=value.

ndarray.__irshift__(/)

Return self>>=value.

ndarray.__iand__(value, /)

Return self&=value.

ndarray.__ior__(/)

Return self|=value.

ndarray.__ixor__(/)

Return self^=value.

Matrix Multiplication:

ndarray.__matmul__(value, /)

Return self@value.

Special methods#

For standard library functions:

ndarray.__copy__()

Used if copy.copy() is called on an array.

ndarray.__deepcopy__(memo, /)

Deep copy of array.

ndarray.__index__()

ndarray.__reduce__(/)

For pickling.

ndarray.__setstate__(state, /)

For unpickling.

Basic customization:

ndarray.__new__(**kwargs)

ndarray.__array__([dtype], /)

Returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array.

Container customization: (see Indexing)

ndarray.__len__(/)

Return len(self).

ndarray.__getitem__(key, /)

Return self[key].

ndarray.__setitem__(key, value, /)

Set self[key]=value.

ndarray.__contains__(key, /)

Return key in self.

Conversion; .. the operations int(), float() and complex(). They work only on arrays that have one element in them and return the appropriate scalar.

ndarray.__int__(/)

Return int(self).

ndarray.__float__(/)

Return float(self).

ndarray.__complex__(/)

String representations:

ndarray.__str__(/)

Return str(self).

ndarray.__repr__(/)

Return repr(self).