dpnp.zeros_like

dpnp.zeros_like(a, /, *, dtype=None, order='K', subok=False, shape=None, device=None, usm_type=None, sycl_queue=None)[source]

Return an array of zeros with the same shape and type as a given array.

For full documentation refer to numpy.zeros_like.

Parameters:
a{dpnp.ndarray, usm_ndarray}

The shape and dtype of a define these same attributes of the returned array.

dtype{None, str, dtype object}, optional

The desired dtype for the array, e.g., dpnp.int32. If None, uses a default floating point data type for the device on which the input array is allocated.

Default: None.

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

Memory layout of the newly output array. order=None is an alias for order="K".

Default: "K".

shape{None, int, sequence of ints}

Overrides the shape of the result.

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 of zeros with the same shape and type as a.

Limitations

Parameter subok is supported only with default value False. 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.full_like

Return a new array with shape of input filled with value.

dpnp.zeros

Return a new array setting values to zero.

Examples

>>> import dpnp as np
>>> x0 = np.arange(6)
>>> x0
array([0, 1, 2, 3, 4, 5])
>>> np.zeros_like(x0)
array([0, 0, 0, 0, 0, 0])

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

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