dpnp.tri

dpnp.tri(N, /, M=None, k=0, dtype=<class 'numpy.float64'>, *, device=None, usm_type='device', sycl_queue=None)[source]

An array with ones at and below the given diagonal and zeros elsewhere.

For full documentation refer to numpy.tri.

Parameters:
  • N (int) -- Number of rows in the array.

  • M (int, optional) -- Number of columns in the array. By default, M is taken equal to N.

  • k (int, optional) -- The sub-diagonal at and below which the array is filled. k = 0 is the main diagonal, while k < 0 is below it, and k > 0 is above. The default is 0.

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

  • usm_type ({None, "device", "shared", "host"}, optional) -- The type of SYCL USM allocation for the output array. Default is "device".

  • sycl_queue ({None, SyclQueue}, optional) -- A SYCL queue to use for output array allocation and copying.

Returns:

out -- Array with its lower triangle filled with ones and zeros elsewhere.

Return type:

dpnp.ndarray of shape (N, M)

See also

dpnp.tril

Return lower triangle of an array.

dpnp.triu

Return upper triangle of an array.

Examples

>>> import dpnp as np
>>> np.tri(3, 5, 2, dtype=int)
array([[1, 1, 1, 0, 0],
       [1, 1, 1, 1, 0],
       [1, 1, 1, 1, 1]])
>>> np.tri(3, 5, -1)
array([[0.,  0.,  0.,  0.,  0.],
       [1.,  0.,  0.,  0.,  0.],
       [1.,  1.,  0.,  0.,  0.]])

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

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