dpnp.zeros
- dpnp.zeros(shape, *, dtype=None, order='C', like=None, device=None, usm_type='device', sycl_queue=None)[source]
Return a new array of given shape and type, filled with zeros.
For full documentation refer to
numpy.zeros
.- Parameters:
shape ({int, sequence of ints}) -- Shape of the new array, e.g., (2, 3) or 2.
dtype ({None, dtype}, optional) -- The desired dtype for the array, e.g., dpnp.int32. Default is the default floating point data type for the device where input array is allocated.
order ({None, "C", "F"}, optional) -- Memory layout of the newly output array. Default:
"C"
.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:
"device"
.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 -- Array of zeros with the given shape, dtype, and order.
- Return type:
dpnp.ndarray
Limitations
Parameter like is supported only with default value
None
. Otherwise, the function raisesNotImplementedError
exception.See also
dpnp.zeros_like
Return an array of zeros with shape and type of input.
dpnp.empty
Return a new uninitialized array.
dpnp.ones
Return a new array setting values to one.
dpnp.full
Return a new array of given shape filled with value.
Examples
>>> import dpnp as np >>> np.zeros(5) array([0., 0., 0., 0., 0.]) >>> x = np.zeros((2, 1)) >>> x.ndim, x.size, x.shape (2, 2, (2, 1)) >>> x array([[0.], [0.]])
Creating an array on a different device or with a specified usm_type
>>> x = np.zeros(3) # default case >>> x, x.device, x.usm_type (array([0., 0., 0.]), Device(level_zero:gpu:0), 'device')
>>> y = np.zeros(3, device="cpu") >>> y, y.device, y.usm_type (array([0., 0., 0.]), Device(opencl:cpu:0), 'device')
>>> z = np.zeros(3, usm_type="host") >>> z, z.device, z.usm_type (array([0., 0., 0.]), Device(level_zero:gpu:0), 'host')