mindspore.ops.eye
- mindspore.ops.eye(n, m=None, dtype=None)[source]
Returns a tensor with ones on the diagonal and zeros in the rest.
- Parameters
n (int) – The number of rows returned.
m (int, optional) – The number of columns returned. If
None
, the number of columns is as the same as n.dtype (mindspore.dtype, optional) – The data type returned.
- Returns
Tensor
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> output = mindspore.ops.eye(3) >>> print(output) [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]] >>> >>> output = mindspore.ops.eye(3, 4) >>> print(output) [[1. 0. 0. 0.] [0. 1. 0. 0.] [0. 0. 1. 0.]]