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). Default: None.

  • copy ({None, bool}, optional) -- If True, then the array data is copied. If None, a copy will only be made if a copy is needed to satisfy any of the requirements (dtype, order, etc.). For False it raises a ValueError exception if a copy can not be avoided. Default: True.

  • order ({"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}, 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 of dpctl.SyclDevice corresponding to a non-partitioned SYCL device, an instance of dpctl.SyclQueue, or a Device object returned by dpnp.dpnp_array.dpnp_array.device property. 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:

dpnp.ndarray

Limitations

Parameter subok is supported only with default value False. Parameter like is supported only with default value None. 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])

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')