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:
- 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 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.- 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:
None.
- Returns:
- outdpnp.ndarray
Array interpretation of a. No copy is performed if the input is already an ndarray with matching dtype and order.
Limitations
Parameter like is supported only with default value
None. Otherwise, the function raisesNotImplementedErrorexception.See also
dpnp.asanyarraySimilar function which passes through subclasses.
dpnp.ascontiguousarrayConvert input to a contiguous array.
dpnp.asfortranarrayConvert input to an ndarray with column-majors memory order.
dpnp.asarray_chkfiniteSimilar function which checks input for NaNs and Infs.
dpnp.fromiterCreate an array from an iterator.
dpnp.fromfunctionConstruct 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')