dpnp.array¶
- dpnp.array(a, dtype=None, *, copy=True, order='K', subok=False, ndmin=0, ndmax=0, like=None, device=None, usm_type=None, sycl_queue=None)[source]¶
Create an array.
For full documentation refer to
numpy.array.- Parameters:
a (array_like) -- Input data, in any form that can be converted to an array. This includes scalars, lists, lists of tuples, tuples, tuples of tuples, tuples of lists, and ndarrays.
dtype ({None, str, dtype object}, optional) --
The desired dtype for the array. If not given, a default dtype will be used that can represent the values (by considering Promotion Type Rule and device capabilities when necessary).
Default:
None.copy ({None, bool}, optional) --
If
True, then the array data is copied. IfNone, a copy will only be made if a copy is needed to satisfy any of the requirements (dtype,order, etc.). ForFalseit raises aValueErrorexception if a copy can not be avoided.Default:
True.order ({None, "C", "F", "A", "K"}, optional) --
Memory layout of the newly output array.
Default:
"K".ndmin (int, optional) --
Specifies the minimum number of dimensions that the resulting array should have. Ones will be prepended to the shape as needed to meet this requirement.
Default:
0.device ({None, string, SyclDevice, SyclQueue, Device}, optional) --
An array API concept of device where the output array is created. device can be
None, a oneAPI filter selector string, an instance ofdpctl.SyclDevicecorresponding to a non-partitioned SYCL device, an instance ofdpctl.SyclQueue, or adpnp.tensor.Deviceobject returned bydpnp.ndarray.device.Default:
None.usm_type ({None, "device", "shared", "host"}, optional) --
The type of SYCL USM allocation for the output array.
Default:
None.sycl_queue ({None, SyclQueue}, optional) --
A SYCL queue to use for output array allocation and copying. The sycl_queue can be passed as
None(the default), which means to get the SYCL queue from device keyword if present or to use a default queue.Default:
None.
- Returns:
out -- An array object satisfying the specified requirements.
- Return type:
Limitations
Parameter subok is supported only with default value
False. Parameter ndmax is supported only with default value0. Parameter like is supported only with default valueNone. Otherwise, the function raisesNotImplementedErrorexception.See also
dpnp.empty_likeReturn an empty array with shape and type of input.
dpnp.ones_likeReturn an array of ones with shape and type of input.
dpnp.zeros_likeReturn an array of zeros with shape and type of input.
dpnp.full_likeReturn a new array with shape of input filled with value.
dpnp.emptyReturn a new uninitialized array.
dpnp.onesReturn a new array setting values to one.
dpnp.zerosReturn a new array setting values to zero.
dpnp.fullReturn a new array of given shape filled with value.
Examples
>>> import dpnp as np >>> x = np.array([1, 2, 3]) >>> x.ndim, x.size, x.shape (1, 3, (3,)) >>> x array([1, 2, 3])
Upcasting:
>>> np.array([1, 2, 3.0]) array([ 1., 2., 3.])
More than one dimension:
>>> x2 = np.array([[1, 2], [3, 4]]) >>> x2.ndim, x2.size, x2.shape (2, 4, (2, 2)) >>> x2 array([[1, 2], [3, 4]])
Minimum dimensions 2:
>>> np.array([1, 2, 3], ndmin=2) array([[1, 2, 3]])
Type provided:
>>> np.array([1, 2, 3], dtype=complex) array([ 1.+0.j, 2.+0.j, 3.+0.j])
Creating an array on a different device or with a specified usm_type
>>> x = np.array([1, 2, 3]) # default case >>> x, x.device, x.usm_type (array([1, 2, 3]), Device(level_zero:gpu:0), 'device')
>>> y = np.array([1, 2, 3], device="cpu") >>> y, y.device, y.usm_type (array([1, 2, 3]), Device(opencl:cpu:0), 'device')
>>> z = np.array([1, 2, 3], usm_type="host") >>> z, z.device, z.usm_type (array([1, 2, 3]), Device(level_zero:gpu:0), 'host')