dpnp.dparray.dparray
- class dpnp.dparray.dparray
Multi-dimensional array using USM interface for an Intel GPU device.
This class implements a subset of methods of
numpy.ndarray
. The difference is that this class allocates the array content useing USM interface on the current GPU device.- Parameters
shape (tuple of ints) – Length of axes.
dtype – Data type. It must be an argument of
numpy.dtype
.memptr (char *) – Pointer to the array content head.
strides (tuple of ints or None) – Strides of data in memory.
order ({'C', 'F'}) – Row-major (C-style) or column-major (Fortran-style) order.
- Variables
~dparray.base (None or dpnp.dparray) – Base array from which this array is created as a view.
~dparray.data (char *) – Pointer to the array content head.
~dparray.dtype (numpy.dtype) –
Dtype object of elements type.
See also
~dparray.size (int) –
Number of elements this array holds.
This is equivalent to product over the shape tuple.
See also
Methods
- __getitem__()
Get the array item(s) x.__getitem__(key) <==> x[key]
- __setitem__()
Set the array item(s) x.__setitem__(key, value) <==> x[key] = value
- __len__()
Returns the size of the first dimension. Equivalent to shape[0] and also equal to size only for one-dimensional arrays.
See also
- __next__()
- __iter__()
Implement iter(self).
- all()
Returns True if all elements evaluate to True.
Refer to numpy.all for full documentation.
See also
numpy.all
equivalent function
- any()
Returns True if any of the elements of a evaluate to True.
Refer to numpy.any for full documentation.
See also
numpy.any
equivalent function
- argmax()
Returns array of indices of the maximum values along the given axis.
- Parameters
axis ({None, integer}) – If None, the index is into the flattened array, otherwise along the specified axis
out ({None, array}, optional) – Array into which the result can be placed. Its type is preserved and it must be of the right shape to hold the output.
- Returns
index_array
- Return type
{integer_array}
Examples
>>> a = np.arange(6).reshape(2,3) >>> a.argmax() 5 >>> a.argmax(0) array([1, 1, 1]) >>> a.argmax(1) array([2, 2])
- argmin()
Return array of indices to the minimum values along the given axis.
- Parameters
axis ({None, integer}) – If None, the index is into the flattened array, otherwise along the specified axis
out ({None, array}, optional) – Array into which the result can be placed. Its type is preserved and it must be of the right shape to hold the output.
- Returns
If multi-dimension input, returns a new ndarray of indices to the minimum values along the given axis. Otherwise, returns a scalar of index to the minimum values along the given axis.
- Return type
ndarray or scalar
- argsort()
Return an ndarray of indices that sort the array along the specified axis.
- Parameters
axis (int, optional) –
Axis along which to sort. If None, the default, the flattened array is used. .. versionchanged:: 1.13.0
Previously, the default was documented to be -1, but that was in error. At some future date, the default will change to -1, as originally intended. Until then, the axis should be given explicitly when
arr.ndim > 1
, to avoid a FutureWarning.kind ({'quicksort', 'mergesort', 'heapsort', 'stable'}, optional) – The sorting algorithm used.
order (list, optional) – When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. Not all fields need be specified.
- Returns
index_array – Array of indices that sort a along the specified axis. In other words,
a[index_array]
yields a sorted a.- Return type
ndarray, int
See also
MaskedArray.sort
Describes sorting algorithms used.
dpnp.lexsort
Indirect stable sort with multiple keys.
numpy.ndarray.sort
Inplace sort.
Notes
See sort for notes on the different sorting algorithms.
- astype()
Copy the array with data type casting.
- Parameters
dtype – Target type.
order ({'C', 'F', 'A', 'K'}) – Row-major (C-style) or column-major (Fortran-style) order. When
order
is ‘A’, it uses ‘F’ ifa
is column-major and uses ‘C’ otherwise. And whenorder
is ‘K’, it keeps strides as closely as possible.copy (bool) – If it is False and no cast happens, then this method returns the array itself. Otherwise, a copy is returned.
- Returns
If
copy
is False and no cast is required, then the array itself is returned. Otherwise, it returns a (possibly casted) copy of the array.
Note
This method currently does not support order`, casting`,
copy
, andsubok
arguments.See also
- choose()
Construct an array from an index array and a set of arrays to choose from.
- conj()
Complex-conjugate all elements.
For full documentation refer to
numpy.ndarray.conj
.
- conjugate()
Return the complex conjugate, element-wise.
For full documentation refer to
numpy.ndarray.conjugate
.
- copy()
Return a copy of the array.
- cumprod()
- cumsum()
- diagonal()
Return specified diagonals.
- fill()
Fill the array with a scalar value.
- Parameters
value (scalar) – All elements of a will be assigned this value.
Examples
>>> a = np.array([1, 2]) >>> a.fill(0) >>> a array([0, 0]) >>> a = np.empty(2) >>> a.fill(1) >>> a array([1., 1.])
- flatten()
Return a copy of the array collapsed into one dimension.
- Parameters
order ({'C', 'F', 'A', 'K'}, optional) – ‘C’ means to flatten in row-major (C-style) order. ‘F’ means to flatten in column-major (Fortran- style) order. ‘A’ means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. ‘K’ means to flatten a in the order the elements occur in memory. The default is ‘C’.
- Returns
out – A copy of the input array, flattened to one dimension.
- Return type
ndarray
See also
dpnp.ravel
,dpnp.flat
- item()
Copy an element of an array to a standard Python scalar and return it.
For full documentation refer to
numpy.ndarray.item
.Examples
>>> np.random.seed(123) >>> x = np.random.randint(9, size=(3, 3)) >>> x array([[2, 2, 6], [1, 3, 6], [1, 0, 1]]) >>> x.item(3) 1 >>> x.item(7) 0 >>> x.item((0, 1)) 2 >>> x.item((2, 2)) 1
- max()
Return the maximum along an axis.
- mean()
Returns the average of the array elements.
- min()
Return the minimum along a given axis.
- partition()
Return a partitioned copy of an array. For full documentation refer to
numpy.partition
.Limitations
Input array is supported as
dpnp.ndarray
. Input kth is supported asint
. Parametersaxis
,kind
andorder
are supported only with default values.
- prod()
Returns the prod along a given axis.
See also
dpnp.prod
for full documentation,dpnp.dparray.sum()
- ptp()
- ravel()
Return a contiguous flattened array.
- Parameters
order ({'C', 'F', 'A', 'K'}, optional) – ‘C’ means to flatten in row-major (C-style) order. ‘F’ means to flatten in column-major (Fortran- style) order. ‘A’ means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. ‘K’ means to flatten a in the order the elements occur in memory. The default is ‘C’.
- Returns
out – A copy of the input array, flattened to one dimension.
- Return type
ndarray
Notes
Unlike the free function
dpnp.reshape
, this method ondpnp.ndarray
allows the elements of the shape parameter to be passed in as separate arguments. For example,a.reshape(10, 11)
is equivalent toa.reshape((10, 11))
.See also
dpnp.ravel
,dpnp.flat
- repeat()
Repeat elements of an array.
See also
dpnp.repeat
for full documentation,numpy.ndarray.repeat()
- reshape()
Change the shape of the array.
See also
- round()
Return array with each element rounded to the given number of decimals.
See also
dpnp.around
for full documentation.
- sort()
Sort the array
- Parameters
a (array_like) – Array to be sorted.
axis (int, optional) – Axis along which to sort. If None, the array is flattened before sorting. The default is -1, which sorts along the last axis.
kind ({'quicksort', 'mergesort', 'heapsort', 'stable'}, optional) – The sorting algorithm used.
order (list, optional) – When a is a structured array, this argument specifies which fields to compare first, second, and so on. This list does not need to include all of the fields.
- Returns
sorted_array – Array of the same type and shape as a.
- Return type
ndarray
See also
numpy.ndarray.sort
Method to sort an array in-place.
dpnp.argsort
Indirect sort.
dpnp.lexsort
Indirect stable sort on multiple keys.
dpnp.searchsorted
Find elements in a sorted array.
Notes
See
sort
for notes on the different sorting algorithms.
- squeeze()
Remove single-dimensional entries from the shape of an array.
See also
dpnp.squeeze
for full documentation
- std()
Returns the variance of the array elements, along given axis.
See also
dpnp.var
for full documentation,
- sum()
Returns the sum along a given axis.
See also
dpnp.sum
for full documentation,dpnp.dparray.sum()
- take()
Take elements from an array. For full documentation refer to
numpy.take
.
- tobytes()
Construct Python bytes containing the raw data bytes in the array.
For full documentation refer to
numpy.ndarray.tobytes
.Examples
>>> import dpnp as np >>> x = np.array([[0, 1], [2, 3]], dtype='<u2') >>> x.tobytes() b'
- tofile()
Write array to a file as text or binary (default).
For full documentation refer to
numpy.ndarray.tofile
.
- tolist()
Return the array as an
a.ndim
-levels deep nested list of Python scalars.For full documentation refer to
numpy.ndarray.tolist
.Examples
>>> import dpnp as np For a 1D array, ``a.tolist()`` is almost the same as ``list(a)``, except that ``tolist`` changes numpy scalars to Python scalars:
>>> a = np.uint32([1, 2]) >>> a_list = list(a) >>> a_list [1, 2] >>> type(a_list[0]) <class 'numpy.uint32'> >>> a_tolist = a.tolist() >>> a_tolist [1, 2] >>> type(a_tolist[0]) <class 'int'>
Additionally, for a 2D array,
tolist
applies recursively:>>> a = np.array([[1, 2], [3, 4]]) >>> list(a) [array([1, 2]), array([3, 4])] >>> a.tolist() [[1, 2], [3, 4]]
The base case for this recursion is a 0D array:
>>> a = np.array(1) >>> list(a) Traceback (most recent call last): ... TypeError: iteration over a 0-d array >>> a.tolist() 1
- tostring()
Construct Python bytes containing the raw data bytes in the array.
This function is a compatibility alias for tobytes. Despite its name it returns bytes not strings.
For full documentation refer to
numpy.ndarray.tostring
.
- transpose()
Returns a view of the array with axes permuted.
See also
dpnp.transpose
for full documentation,numpy.ndarray.reshape()
- var()
Returns the variance of the array elements along given axis.
Masked entries are ignored, and result elements which are not finite will be masked.
Refer to numpy.var for full documentation.
See also
numpy.ndarray.var
corresponding function for ndarrays
numpy.var
Equivalent function
- __eq__(value, /)
Return self==value.
- __ne__(value, /)
Return self!=value.
- __lt__(value, /)
Return self<value.
- __le__(value, /)
Return self<=value.
- __gt__(value, /)
Return self>value.
- __ge__(value, /)
Return self>=value.
Attributes
- T
Shape-reversed view of the array.
If ndim < 2, then this is just a reference to the array itself.
- dtype
Type of the elements in the array
- flags
Object containing memory-layout information.
It only contains
c_contiguous
,f_contiguous
, andowndata
attributes. All of these are read-only. Accessing by indexes is also supported.See also
- flat
Return a flat iterator, or set a flattened version of self to value.
- itemsize
Size of each element in bytes.
See also
- nbytes
Total size of all elements in bytes.
It does not count strides or alignment of elements.
See also
- ndim
Number of dimensions.
a.ndim
is equivalent tolen(a.shape)
.See also
- shape
Lengths of axes. A tuple of numbers represents size of each dimention.
Setter of this property involves reshaping without copy. If the array cannot be reshaped without copy, it raises an exception.
- size
Number of elements in the array.
See also
- strides
Strides of axes in bytes.
See also