dpnp.identity
- dpnp.identity(n, /, dtype=None, *, like=None, device=None, usm_type='device', sycl_queue=None)[source]
Return the identity array.
The identity array is a square array with ones on the main diagonal.
For full documentation refer to
numpy.identity
.- Parameters:
n (int) -- Number of rows (and columns) in n x n output.
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.
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 -- n x n array with its main diagonal set to one, and all other elements 0.
- Return type:
dpnp.ndarray
Limitations
Parameter like is currently not supported. Otherwise, the function raises
NotImplementedError
exception.See also
Examples
>>> import dpnp as np >>> np.identity(3) array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])
Creating an array on a different device or with a specified usm_type
>>> x = np.identity(3) # default case >>> x, x.device, x.usm_type (array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), Device(level_zero:gpu:0), 'device')
>>> y = np.identity(3, device="cpu") >>> y, y.device, y.usm_type (array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), Device(opencl:cpu:0), 'device')
>>> z = np.identity(3, usm_type="host") >>> z, z.device, z.usm_type (array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), Device(level_zero:gpu:0), 'host')