mindspore.ops.Eye

View Source On Gitee
class mindspore.ops.Eye[source]

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

Refer to mindspore.ops.eye() for more details.

Inputs:
  • n (int) - The number of rows of returned tensor. Constant value only.

  • m (int) - The number of columns of returned tensor. Constant value only.

  • t (mindspore.dtype) - MindSpore’s dtype, the data type of the returned tensor. Default: None , the data type of the returned tensor is mindspore.float32.

Outputs:

Tensor, a tensor with ones on the diagonal and the rest of elements are zero. The shape of output depends on the user’s Inputs n and m. And the data type depends on Inputs t.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import ops
>>> eye = ops.Eye()
>>> output = eye(2, 2, mindspore.int32)
>>> print(output)
[[1 0]
 [0 1]]
>>> print(output.dtype)
Int32
>>> output = eye(1, 2, mindspore.float64)
>>> print(output)
[[1. 0.]]
>>> print(output.dtype)
Float64