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
- all(axis=None, out=None, keepdims=False, *, where=True)[source]
Returns True if all elements evaluate to True.
Refer to
dpnp.allfor full documentation.See also
dpnp.allequivalent 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.anyfor full documentation.See also
dpnp.anyequivalent function
- argmax(axis=None, out=None, *, keepdims=False)[source]
Returns array of indices of the maximum values along the given axis.
Refer to
dpnp.argmaxfor 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.argminfor 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.argsortfor full documentation.
- asnumpy()[source]
Copy content of the array into
numpy.ndarrayinstance of the same shape and data type.- Returns:
An instance of
numpy.ndarraypopulated with the array content.- Return type:
- astype(dtype, order='K', casting='unsafe', subok=True, copy=True, device=None)[source]
Copy the array with data type casting.
Refer to
dpnp.astypefor 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
orderis 'A', it uses 'F' ifais column-major and uses 'C' otherwise. And whenorderis '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,
astypealways returns a newly allocated array. If this is set toFalse, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy.device ({None, string, SyclDevice, SyclQueue}, optional) -- An array API concept of device where the output array is created. The device can be
None(the default), an OneAPI filter selector string, an instance ofdpctl.SyclDevicecorresponding to a non-partitioned SYCL device, an instance ofdpctl.SyclQueue, or a Device object returned bydpnp.dpnp_array.dpnp_array.deviceproperty. Default:None.
- Returns:
arr_t -- Unless copy is
Falseand 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
NotImplementedErrorexception 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.choosefor full documentation.
- clip(min=None, max=None, out=None, **kwargs)[source]
Clip (limit) the values in an array.
Refer to
dpnp.clipfor full documentation.
- conj()[source]
Complex-conjugate all elements.
Refer to
dpnp.conjugatefor full documentation.
- conjugate()[source]
Return the complex conjugate, element-wise.
Refer to
dpnp.conjugatefor 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.copySimilar function with different default behavior
dpnp.copytoCopies 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
- cumprod(axis=None, dtype=None, out=None)[source]
Return the cumulative product of the elements along the given axis.
Refer to
dpnp.cumprodfor full documentation.
- cumsum(axis=None, dtype=None, out=None)[source]
Return the cumulative sum of the elements along the given axis.
Refer to
dpnp.cumsumfor full documentation.
- diagonal(offset=0, axis1=0, axis2=1)[source]
Return specified diagonals.
Refer to
dpnp.diagonalfor full documentation.See also
dpnp.diagonalEquivalent function.
Examples
>>> import dpnp as np >>> a = np.arange(4).reshape(2,2) >>> a.diagonal() array([0, 3])
- dot(b, out=None)[source]
Dot product of two arrays.
Refer to
dpnp.dotfor 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.
For full documentation refer to
numpy.ndarray.flatten.- Parameters:
order ({"C", "F"}, optional) --
Read the elements using this index order, and place the elements into the reshaped array using this index order.
"C" means to read / write the elements using C-like index order, with the last axis index changing fastest, back to the first axis index changing slowest.
"F" means to read / write the elements using Fortran-like index order, with the first index changing fastest, and the last index changing slowest.
The default is
"C".- Returns:
out -- A copy of the input array, flattened to one dimension.
- Return type:
dpnp.ndarray
See also
dpnp.ravelReturn a flattened array.
dpnp.flatA 1-D flat iterator over the array.
Examples
>>> import dpnp as np >>> a = np.array([[1, 2], [3, 4]]) >>> a.flatten() array([1, 2, 3, 4]) >>> a.flatten("F") array([1, 3, 2, 4])
- 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.maxfor full documentation.
- mean(axis=None, dtype=None, out=None, keepdims=False, *, where=True)[source]
Returns the average of the array elements.
Refer to
dpnp.meanfor full documentation.
- min(axis=None, out=None, keepdims=False, initial=None, where=True)[source]
Return the minimum along a given axis.
Refer to
dpnp.minfor full documentation.
- nonzero()[source]
Return the indices of the elements that are non-zero.
Refer to
dpnp.nonzerofor 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.partitionReturn 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.prodfor 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.putfor full documentation.
- ravel(order='C')[source]
Return a contiguous flattened array.
Refer to
dpnp.ravelfor full documentation.
- repeat(repeats, axis=None)[source]
Repeat elements of an array.
Refer to
dpnp.repeatfor full documentation.
- reshape(*sh, **kwargs)[source]
Returns an array containing the same data with a new shape.
Refer to
dpnp.reshapefor 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.reshapeEquivalent 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 toa.reshape((10, 11)).
- round(decimals=0, out=None)[source]
Return array with each element rounded to the given number of decimals.
Refer to
dpnp.roundfor 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.searchsortedfor full documentation
- sort(axis=-1, kind=None, order=None)[source]
Sort an array in-place.
Refer to
dpnp.sortfor full documentation.Note
axis in
dpnp.sortcould be integer orNone. IfNone, the array is flattened before sorting. However, axis indpnp.ndarray.sortcan 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.squeezefor 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.stdfor 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.sumfor full documentation.
- swapaxes(axis1, axis2)[source]
Interchange two axes of an array.
Refer to
dpnp.swapaxesfor full documentation.
- take(indices, /, *, axis=None, out=None, mode='wrap')[source]
Take elements from an array along an axis.
Refer to
dpnp.takefor full documentation.
- trace(offset=0, axis1=0, axis2=1, dtype=None, out=None)[source]
Return the sum along diagonals of the array.
Refer to
dpnp.tracefor full documentation.
- 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) --
Noneor 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.transposeEquivalent function.
dpnp.ndarray.ndarray.TArray property returning the array transposed.
dpnp.ndarray.reshapeGive 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.varfor full documentation.
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 iss1*s1 + s2*i2 + s3*i3.
- sycl_context
- sycl_device
- sycl_queue
- usm_type