dpnp.dpnp_array.dpnp_array

class dpnp.dpnp_array.dpnp_array(shape, dtype=None, buffer=None, offset=0, strides=None, order='C', device=None, usm_type='device', sycl_queue=None)[source]

Multi-dimensional array object.

This is a wrapper around dpctl.tensor.usm_ndarray that provides methods to be compliant with original NumPy.

Methods

__getitem__(key)[source]

Return self[key].

__setitem__(key, val)[source]

Set self[key] to value.

__len__()[source]

Return len(self).

all(axis=None, out=None, keepdims=False, *, where=True)[source]

Returns True if all elements evaluate to True.

Refer to dpnp.all for full documentation.

See also

dpnp.all

equivalent function

any(axis=None, out=None, keepdims=False, *, where=True)[source]

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

Refer to dpnp.any for full documentation.

See also

dpnp.any

equivalent function

argmax(axis=None, out=None, *, keepdims=False)[source]

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

Refer to dpnp.argmax for full documentation.

argmin(axis=None, out=None, *, keepdims=False)[source]

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

Refer to dpnp.argmin for full documentation.

argsort(axis=-1, kind=None, order=None)[source]

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

Refer to dpnp.argsort for full documentation.

asnumpy()[source]

Copy content of the array into numpy.ndarray instance of the same shape and data type.

Returns:

An instance of numpy.ndarray populated with the array content.

Return type:

numpy.ndarray

astype(dtype, order='K', casting='unsafe', subok=True, copy=True)[source]

Copy the array with data type casting.

Refer to dpnp.astype for full documentation.

Parameters:
  • x1 ({dpnp.ndarray, usm_ndarray}) -- Array data type casting.

  • dtype (dtype) -- Target data type.

  • order ({"C", "F", "A", "K"}, optional) -- Row-major (C-style) or column-major (Fortran-style) order. When order is 'A', it uses 'F' if a is column-major and uses 'C' otherwise. And when order is 'K', it keeps strides as closely as possible.

  • copy ({bool}, optional) -- If it is False and no cast happens, then this method returns the array itself. Otherwise, a copy is returned.

  • casting ({'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional) --

    Controls what kind of data casting may occur. Defaults to 'unsafe' for backwards compatibility.

    • 'no' means the data types should not be cast at all.

    • 'equiv' means only byte-order changes are allowed.

    • 'safe' means only casts which can preserve values are allowed.

    • 'same_kind' means only safe casts or casts within a kind, like float64 to float32, are allowed.

    • 'unsafe' means any data conversions may be done.

  • copy -- By default, astype always returns a newly allocated array. If this is set to False, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy.

Returns:

arr_t -- Unless copy is False and the other conditions for returning the input array are satisfied, arr_t is a new array of the same shape as the input array, with dtype, order given by dtype, order.

Return type:

dpnp.ndarray

Limitations

Parameter subok is supported with default value. Otherwise NotImplementedError exception will be raised.

Examples

>>> import dpnp as np
>>> x = np.array([1, 2, 2.5])
>>> x
array([1. , 2. , 2.5])
>>> x.astype(int)
array([1, 2, 2])
choose(choices, out=None, mode='raise')[source]

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

Refer to dpnp.choose for full documentation.

clip(min=None, max=None, out=None, **kwargs)[source]

Clip (limit) the values in an array.

Refer to dpnp.clip for full documentation.

conj()[source]

Complex-conjugate all elements.

Refer to dpnp.conjugate for full documentation.

conjugate()[source]

Return the complex conjugate, element-wise.

Refer to dpnp.conjugate for full documentation.

copy(order='C')[source]

Return a copy of the array.

Returns:

out -- A copy of the array.

Return type:

dpnp.ndarray

See also

dpnp.copy

Similar function with different default behavior

dpnp.copyto

Copies values from one array to another.

Notes

This function is the preferred method for creating an array copy. The function dpnp.copy() is similar, but it defaults to using order 'K'.

Examples

>>> import dpnp as np
>>> x = np.array([[1, 2, 3], [4, 5, 6]], order='F')
>>> y = x.copy()
>>> x.fill(0)
>>> x
array([[0, 0, 0],
       [0, 0, 0]])
>>> y
array([[1, 2, 3],
       [4, 5, 6]])
>>> y.flags['C_CONTIGUOUS']
True
cumsum(axis=None, dtype=None, out=None)[source]

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

Refer to dpnp.cumsum for full documentation.

diagonal(offset=0, axis1=0, axis2=1)[source]

Return specified diagonals.

Refer to dpnp.diagonal for full documentation.

dot(b, out=None)[source]

Dot product of two arrays.

Refer to dpnp.dot for full documentation.

Examples

>>> import dpnp as np
>>> a = np.eye(2)
>>> b = np.ones((2, 2)) * 2
>>> a.dot(b)
array([[2., 2.],
       [2., 2.]])

This array method can be conveniently chained:

>>> a.dot(b).dot(b)
array([[8., 8.],
       [8., 8.]])
fill(value)[source]

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(order='C')[source]

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

get_array()[source]

Get usm_ndarray object.

item(id=None)[source]

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(axis=None, out=None, keepdims=False, initial=None, where=True)[source]

Return the maximum along an axis.

Refer to dpnp.max for full documentation.

mean(axis=None, dtype=None, out=None, keepdims=False, *, where=True)[source]

Returns the average of the array elements.

Refer to dpnp.mean for full documentation.

min(axis=None, out=None, keepdims=False, initial=None, where=True)[source]

Return the minimum along a given axis.

Refer to dpnp.min for full documentation.

nonzero()[source]

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

Refer to dpnp.nonzero for full documentation.

partition(kth, axis=-1, kind='introselect', order=None)[source]

Return a partitioned copy of an array.

Rearranges the elements in the array in such a way that the value of the element in kth position is in the position it would be in a sorted array.

All elements smaller than the kth element are moved before this element and all equal or greater are moved behind it. The ordering of the elements in the two partitions is undefined.

Refer to dpnp.partition for full documentation.

See also

dpnp.partition

Return a partitioned copy of an array.

Examples

>>> import dpnp as np
>>> a = np.array([3, 4, 2, 1])
>>> a.partition(3)
>>> a
array([1, 2, 3, 4])
prod(axis=None, dtype=None, out=None, keepdims=False, initial=None, where=True)[source]

Returns the prod along a given axis.

Refer to dpnp.prod for full documentation.

put(indices, vals, /, *, axis=None, mode='wrap')[source]

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

Refer to dpnp.put for full documentation.

ravel(order='C')[source]

Return a contiguous flattened array.

Refer to dpnp.ravel for full documentation.

repeat(repeats, axis=None)[source]

Repeat elements of an array.

Refer to dpnp.repeat for full documentation.

reshape(*sh, **kwargs)[source]

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

Refer to dpnp.reshape for full documentation.

Returns:

y -- This will be a new view object if possible; otherwise, it will be a copy.

Return type:

dpnp.ndarray

See also

dpnp.reshape

Equivalent function.

Notes

Unlike the free function dpnp.reshape, this method on ndarray allows the elements of the shape parameter to be passed in as separate arguments. For example, a.reshape(10, 11) is equivalent to a.reshape((10, 11)).

round(decimals=0, out=None)[source]

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

Refer to dpnp.round for full documentation.

searchsorted(v, side='left', sorter=None)[source]

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

Refer to dpnp.searchsorted for full documentation

sort(axis=-1, kind=None, order=None)[source]

Sort an array in-place.

Refer to dpnp.sort for full documentation.

Note

axis in dpnp.sort could be integer or None. If None, the array is flattened before sorting. However, axis in dpnp.ndarray.sort can only be integer since it sorts an array in-place.

Examples

>>> import dpnp as np
>>> a = np.array([[1,4],[3,1]])
>>> a.sort(axis=1)
>>> a
array([[1, 4],
      [1, 3]])
>>> a.sort(axis=0)
>>> a
array([[1, 1],
      [3, 4]])
squeeze(axis=None)[source]

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

Refer to dpnp.squeeze for full documentation

std(axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True)[source]

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

Refer to dpnp.std for full documentation.

sum(axis=None, dtype=None, out=None, keepdims=False, initial=None, where=True)[source]

Returns the sum along a given axis.

Refer to dpnp.sum for full documentation.

swapaxes(axis1, axis2)[source]

Interchange two axes of an array.

Refer to dpnp.swapaxes for full documentation.

take(indices, /, *, axis=None, out=None, mode='wrap')[source]

Take elements from an array along an axis.

Refer to dpnp.take for full documentation.

to_device(target_device)[source]

Transfer array to target device.

transpose(*axes)[source]

Returns a view of the array with axes transposed.

For full documentation refer to numpy.ndarray.transpose.

Parameters:

axes (None, tuple or list of ints, n ints, optional) --

  • None or no argument: reverses the order of the axes.

  • tuple or list of ints: i in the j-th place in the tuple/list means that the array’s i-th axis becomes the transposed array’s j-th axis.

  • n ints: same as an n-tuple/n-list of the same integers (this form is intended simply as a “convenience” alternative to the tuple form).

Returns:

out -- View of the array with its axes suitably permuted.

Return type:

dpnp.ndarray

See also

dpnp.transpose

Equivalent function.

dpnp.ndarray.ndarray.T

Array property returning the array transposed.

dpnp.ndarray.reshape

Give a new shape to an array without changing its data.

Examples

>>> import dpnp as np
>>> a = np.array([[1, 2], [3, 4]])
>>> a
array([[1, 2],
       [3, 4]])
>>> a.transpose()
array([[1, 3],
       [2, 4]])
>>> a.transpose((1, 0))
array([[1, 3],
       [2, 4]])
>>> a = np.array([1, 2, 3, 4])
>>> a
array([1, 2, 3, 4])
>>> a.transpose()
array([1, 2, 3, 4])
var(axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True)[source]

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

Refer to dpnp.var for full documentation.

__eq__(other)[source]

Return self==value.

__ne__(other)[source]

Return self!=value.

__lt__(other)[source]

Return self<value.

__le__(other)[source]

Return self<=value.

__gt__(other)[source]

Return self>value.

__ge__(other)[source]

Return self>=value.

Attributes

T

View of the transposed array.

device
dtype

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

flags

Return information about the memory layout of the array.

flat

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

imag

The imaginary part of the array.

For full documentation refer to numpy.ndarray.imag.

Examples

>>> import dpnp as np
>>> x = np.sqrt(np.array([1+0j, 0+1j]))
>>> x.imag
array([0.        , 0.70710677])
itemsize

Size of one array element in bytes.

nbytes

Total bytes consumed by the elements of the array.

ndim

Number of array dimensions.

real

The real part of the array.

For full documentation refer to numpy.ndarray.real.

Examples

>>> import dpnp as np
>>> x = np.sqrt(np.array([1+0j, 0+1j]))
>>> x.real
array([1.        , 0.70710677])
shape

Lengths of axes. A tuple of numbers represents size of each dimension.

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.

strides

Returns memory displacement in array elements, upon unit change of respective index.

For example, for strides (s1, s2, s3) and multi-index (i1, i2, i3) position of the respective element relative to zero multi-index element is s1*s1 + s2*i2 + s3*i3.

sycl_context
sycl_device
sycl_queue
usm_type