Multi-Dimensional Array (ndarray)

dpnp.ndarray is the DPNP counterpart of NumPy numpy.ndarray.

For the basic concept of ndarrays, please refer to the NumPy documentation.

dpnp.ndarray

alias of dpnp_array

dpnp.dpnp_array.dpnp_array

Multi-dimensional array object.

Constructing arrays

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

dpnp.ndarray

alias of dpnp_array

Indexing arrays

Arrays can be indexed using an extended Python slicing syntax, array[selection].

Array attributes

Array attributes reflect information that is intrinsic to the array itself. Generally, accessing an array through its attributes allows you to get and sometimes set intrinsic properties of the array without creating a new array. The exposed attributes are the core parts of an array and only some of them can be reset meaningfully without creating a new array. Information on each attribute is given below.

Memory layout

The following attributes contain information about the memory layout of the array:

dpnp.ndarray.flags

Return information about the memory layout of the array.

dpnp.ndarray.shape

Lengths of axes.

dpnp.ndarray.strides

Get strides of an array.

dpnp.ndarray.ndim

Number of array dimensions.

dpnp.ndarray.size

Number of elements in the array.

dpnp.ndarray.itemsize

Size of one array element in bytes.

dpnp.ndarray.nbytes

Total bytes consumed by the elements of the array.

Data type

The data type object associated with the array can be found in the dtype attribute:

dpnp.ndarray.dtype

Returns NumPy's dtype corresponding to the type of the array elements.

Other attributes

dpnp.ndarray.T

View of the transposed array.

dpnp.ndarray.real

The real part of the array.

dpnp.ndarray.imag

The imaginary part of the array.

dpnp.ndarray.flat

Return a flat iterator, or set a flattened version of self to value.

Array methods

An dpnp.ndarray object has many methods which operate on or with the array in some fashion, typically returning an array result. These methods are briefly explained below. (Each method’s docstring has a more complete description.)

For the following methods there are also corresponding functions in dpnp: all, any, argmax, argmin, argpartition, argsort, choose, clip, compress, copy, cumprod, cumsum, diagonal, imag, max, mean, min, nonzero, partition, prod, put, ravel, real, repeat, reshape, round, searchsorted, sort, squeeze, std, sum, swapaxes, take, trace, transpose, var.

Array conversion

dpnp.ndarray.item

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

dpnp.ndarray.astype

Copy the array with data type casting.

dpnp.ndarray.copy

Return a copy of the array.

dpnp.ndarray.fill

Fill the array with a scalar value.

Shape manipulation

For reshape, resize, and transpose, the single tuple argument may be replaced with n integers which will be interpreted as an n-tuple.

dpnp.ndarray.reshape

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

dpnp.ndarray.transpose

Returns a view of the array with axes transposed.

dpnp.ndarray.swapaxes

Interchange two axes of an array.

dpnp.ndarray.flatten

Return a copy of the array collapsed into one dimension.

dpnp.ndarray.ravel

Return a contiguous flattened array.

dpnp.ndarray.squeeze

Remove single-dimensional entries from the shape of an array.

Item selection and manipulation

For array methods that take an axis keyword, it defaults to None. If axis is None, then the array is treated as a 1-D array. Any other value for axis represents the dimension along which the operation should proceed.

dpnp.ndarray.take

Take elements from an array along an axis.

dpnp.ndarray.put

Puts values of an array into another array along a given axis.

dpnp.ndarray.repeat

Repeat elements of an array.

dpnp.ndarray.choose

Construct an array from an index array and a set of arrays to choose from.

dpnp.ndarray.sort

Sort an array in-place.

dpnp.ndarray.argsort

Return an ndarray of indices that sort the array along the specified axis.

dpnp.ndarray.partition

Return a partitioned copy of an array.

dpnp.ndarray.searchsorted

Find indices where elements of v should be inserted in a to maintain order.

dpnp.ndarray.nonzero

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

dpnp.ndarray.diagonal

Return specified diagonals.

Calculation

dpnp.ndarray.max

Return the maximum along an axis.

dpnp.ndarray.argmax

Returns array of indices of the maximum values along the given axis.

dpnp.ndarray.min

Return the minimum along a given axis.

dpnp.ndarray.argmin

Return array of indices to the minimum values along the given axis.

dpnp.ndarray.clip

Clip (limit) the values in an array.

dpnp.ndarray.conj

Complex-conjugate all elements.

dpnp.ndarray.conjugate

Return the complex conjugate, element-wise.

dpnp.ndarray.round

Return array with each element rounded to the given number of decimals.

dpnp.ndarray.sum

Returns the sum along a given axis.

dpnp.ndarray.cumsum

Return the cumulative sum of the elements along the given axis.

dpnp.ndarray.mean

Returns the average of the array elements.

dpnp.ndarray.var

Returns the variance of the array elements, along given axis.

dpnp.ndarray.std

Returns the standard deviation of the array elements, along given axis.

dpnp.ndarray.prod

Returns the prod along a given axis.

dpnp.ndarray.all

Returns True if all elements evaluate to True.

dpnp.ndarray.any

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

Arithmetic, matrix multiplication, and comparison operations

Arithmetic and comparison operations on dpnp.ndarrays are defined as element-wise operations, and generally yield dpnp.ndarray objects as results.

Each of the arithmetic operations (+, -, *, /, //, %, divmod(), ** or pow(), <<, >>, &, ^, |, ~) and the comparisons (==, <, >, <=, >=, !=) is equivalent to the corresponding universal function (or ufunc for short) in DPNP. For more information, see the section on Universal Functions.

Comparison operators:

dpnp.ndarray.__lt__

Return self<value.

dpnp.ndarray.__le__

Return self<=value.

dpnp.ndarray.__gt__

Return self>value.

dpnp.ndarray.__ge__

Return self>=value.

dpnp.ndarray.__eq__

Return self==value.

dpnp.ndarray.__ne__

Return self!=value.

Unary operations:

dpnp.ndarray.__neg__

Return -self.

dpnp.ndarray.__pos__

Return +self.

dpnp.ndarray.__abs__

Return |self|.

dpnp.ndarray.__invert__

Return ~self.

Arithmetic:

dpnp.ndarray.__add__

Return self+value.

dpnp.ndarray.__sub__

Return self-value.

dpnp.ndarray.__mul__

Return self*value.

dpnp.ndarray.__truediv__

Return self/value.

dpnp.ndarray.__floordiv__

Return self//value.

dpnp.ndarray.__mod__

Return self%value.

dpnp.ndarray.__pow__

Return self**value.

dpnp.ndarray.__lshift__

Return self<<value.

dpnp.ndarray.__rshift__

Return self>>value.

dpnp.ndarray.__and__

Return self&value.

dpnp.ndarray.__or__

Return self|value.

dpnp.ndarray.__xor__

Return self^value.

Arithmetic, in-place:

dpnp.ndarray.__iadd__

Return self+=value.

dpnp.ndarray.__isub__

Return self-=value.

dpnp.ndarray.__imul__

Return self*=value.

dpnp.ndarray.__itruediv__

Return self/=value.

dpnp.ndarray.__ifloordiv__

Return self//=value.

dpnp.ndarray.__imod__

Return self%=value.

dpnp.ndarray.__ipow__

Return self**=value.

dpnp.ndarray.__ilshift__

Return self<<=value.

dpnp.ndarray.__irshift__

Return self>>=value.

dpnp.ndarray.__iand__

Return self&=value.

dpnp.ndarray.__ior__

Return self|=value.

dpnp.ndarray.__ixor__

Return self^=value.

Special methods

For standard library functions:

dpnp.ndarray.__copy__

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

Basic customization:

dpnp.ndarray.__new__

Container customization: (see Indexing)

dpnp.ndarray.__len__

Return len(self).

dpnp.ndarray.__getitem__

Return self[key].

dpnp.ndarray.__setitem__

Set self[key] to value.

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

dpnp.ndarray.__int__

dpnp.ndarray.__float__

dpnp.ndarray.__complex__

String representations:

dpnp.ndarray.__str__

Output values from the array to standard output.

dpnp.ndarray.__repr__

Return repr(self).