dpnp.asanyarray

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

Convert the input to an dpnp.ndarray.

For full documentation refer to numpy.asanyarray.

Parameters:
aarray_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.

order{None, "C", "F", "A", "K"}, optional

Memory layout of the newly output array.

Default: "K".

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 of dpctl.SyclDevice corresponding to a non-partitioned SYCL device, an instance of dpctl.SyclQueue, or a dpnp.tensor.Device object returned by dpnp.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:
outdpnp.ndarray

Array interpretation of a.

Limitations

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

See also

dpnp.asarray

Similar function which always returns ndarrays.

dpnp.ascontiguousarray

Convert input to a contiguous array.

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.asanyarray([1, 2, 3])
array([1, 2, 3])

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

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