dpnp.asarray

dpnp.asarray(a, dtype=None, order=None, *, device=None, usm_type=None, sycl_queue=None, copy=None, like=None)[source]

Converts an input object into array.

For full documentation refer to numpy.asarray.

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.

  • order ({None, "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 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.

  • 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.

Returns:

out -- Array interpretation of a. No copy is performed if the input is already an ndarray with matching dtype and order.

Return type:

dpnp.ndarray

Limitations

Parameter like is supported only with default value None. Otherwise, the function raises NotImplementedError exception.

See also

dpnp.asanyarray

Similar function which passes through subclasses.

dpnp.ascontiguousarray

Convert input to a contiguous array.

dpnp.asfarray

Convert input to a floating point ndarray.

dpnp.asfortranarray

Convert input to an ndarray with column-major memory order.

dpnp.asarray_chkfinite

Similar function which checks input for NaNs and Infs.

dpnp.fromiter

Create an array from an iterator.

dpnp.fromfunction

Construct an array by executing a function on grid positions.

Examples

>>> import dpnp as np
>>> np.asarray([1, 2, 3])
array([1, 2, 3])

Creating an array on a different device or with a specified usm_type

>>> x = np.asarray([1, 2, 3]) # default case
>>> x, x.device, x.usm_type
(array([1, 2, 3]), Device(level_zero:gpu:0), 'device')
>>> y = np.asarray([1, 2, 3], device="cpu")
>>> y, y.device, y.usm_type
(array([1, 2, 3]), Device(opencl:cpu:0), 'device')
>>> z = np.asarray([1, 2, 3], usm_type="host")
>>> z, z.device, z.usm_type
(array([1, 2, 3]), Device(level_zero:gpu:0), 'host')