Multi-Dimensional Array (ndarray)
dpnp.ndarray
is the DPNP counterpart of NumPy numpy.ndarray
.
For the basic concept of ndarray
s, please refer to the NumPy documentation.
alias of |
|
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:
alias of |
Indexing arrays
Arrays can be indexed using an extended Python slicing syntax,
array[selection]
.
See also
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:
Return information about the memory layout of the array. |
|
Tuple of array dimensions. |
|
Returns memory displacement in array elements, upon unit change of respective index. |
|
Return the number of dimensions of an array. |
|
Number of elements in the array. |
|
Size of one array element in bytes. |
|
Total bytes consumed by the elements of the array. |
Data type
See also
The data type object associated with the array can be found in the
dtype
attribute:
Returns NumPy's dtype corresponding to the type of the array elements. |
Other attributes
View of the transposed array. |
|
View of the matrix transposed array. |
|
The real part of the array. |
|
The imaginary part of the array. |
|
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
Copy an element of an array to a standard Python scalar and return it. |
|
Copy the array with data type casting. |
|
Return a copy of the array. |
|
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.
Returns an array containing the same data with a new shape. |
|
Returns a view of the array with axes transposed. |
|
Interchange two axes of an array. |
|
Return a copy of the array collapsed into one dimension. |
|
Return a contiguous flattened array. |
|
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.
Take elements from an array along an axis. |
|
Puts values of an array into another array along a given axis. |
|
Repeat elements of an array. |
|
Construct an array from an index array and a set of arrays to choose from. |
|
Sort an array in-place. |
|
Return an ndarray of indices that sort the array along the specified axis. |
|
Return a partitioned copy of an array. |
|
Find indices where elements of v should be inserted in a to maintain order. |
|
Return the indices of the elements that are non-zero. |
|
Return specified diagonals. |
Calculation
Return the maximum along an axis. |
|
Returns array of indices of the maximum values along the given axis. |
|
Return the minimum along a given axis. |
|
Return array of indices to the minimum values along the given axis. |
|
Clip (limit) the values in an array. |
|
Complex-conjugate all elements. |
|
Return the complex conjugate, element-wise. |
|
Return array with each element rounded to the given number of decimals. |
|
Return the sum along diagonals of the array. |
|
Returns the sum along a given axis. |
|
Return the cumulative sum of the elements along the given axis. |
|
Returns the average of the array elements. |
|
Returns the variance of the array elements, along given axis. |
|
Returns the standard deviation of the array elements, along given axis. |
|
Returns the prod along a given axis. |
|
Return the cumulative product of the elements along the given axis. |
|
Returns True if all elements evaluate to True. |
|
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:
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
Truth value of an array (bool()
):
|
Note
Truth-value testing of an array invokes
dpnp.ndarray.__bool__()
, which raises an error if the number of
elements in the array is not 1, because the truth value
of such arrays is ambiguous. Use .any()
and
.all()
instead to be clear about what is meant
in such cases. (If you wish to check for whether an array is empty,
use for example .size > 0
.)
Unary operations:
Return |
|
Return |
|
Return |
|
Return |
Arithmetic:
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
Arithmetic, reflected:
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
Arithmetic, in-place:
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
Matrix Multiplication:
|
Return |
|
Return |
|
Return |
Special methods
For standard library functions:
Used if |
Basic customization:
Container customization: (see Indexing)
Return |
|
Return |
|
Set |
Conversion; the operations int()
,
float()
and complex()
.
They work only on arrays that have one element in them
and return the appropriate scalar.
String representations:
Return |
|
Return |