dpnp.array
- dpnp.array(a, dtype=None, *, copy=True, order='K', subok=False, ndmin=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, dtype}, 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).
copy (bool, optional) -- If
True
(default), then the object is copied.order ({"C", "F", "A", "K"}, optional) -- Memory layout of the newly output array. Default: "K".
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.SyclDevice
corresponding to a non-partitioned SYCL device, an instance ofdpctl.SyclQueue
, or a Device object returned bydpnp.dpnp_array.dpnp_array.device
property.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.
- Returns:
out -- An array object satisfying the specified requirements.
- Return type:
dpnp.ndarray
Limitations
Parameter subok is supported only with default value
False
. Parameter ndmin is supported only with default value0
. Parameter like is supported only with default valueNone
. Otherwise, the function raises NotImplementedError exception.See also
dpnp.empty_like
Return an empty array with shape and type of input.
dpnp.ones_like
Return an array of ones with shape and type of input.
dpnp.zeros_like
Return an array of zeros with shape and type of input.
dpnp.full_like
Return a new array with shape of input filled with value.
dpnp.empty
Return a new uninitialized array.
dpnp.ones
Return a new array setting values to one.
dpnp.zeros
Return a new array setting values to zero.
dpnp.full
Return 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])
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]])
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')