mindspore.ops.Eye

class mindspore.ops.Eye(*args, **kwargs)[source]

Creates a tensor with ones on the diagonal and zeros the rest.

Inputs:
  • n (int) - The number of rows of returned tensor

  • m (int) - The number of columns of returned tensor

  • t (mindspore.dtype) - MindSpore’s dtype, The data type of the returned tensor.

Outputs:

Tensor, a tensor with ones on the diagonal and the rest of elements are zero.

Raises
Supported Platforms:

Ascend GPU CPU

Examples

>>> eye = ops.Eye()
>>> output = eye(2, 2, mindspore.int32)
>>> print(output)
[[1 0]
 [0 1]]