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. only constant value.
m (int) - The number of columns of returned tensor. only constant value.
t (mindspore.dtype) - MindSpore’s dtype, The data type of the returned tensor. The data type can be Number.
- 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.
- Raises
TypeError – If m or n is not an int.
ValueError – If m or n is less than 1.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> 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 >>> # if wants a anti-diagonal >>> anti_diagonal_input = eye(2, 2, mindspore.int32) >>> # Note that ReverseV2 only supports "Ascend" at this time >>> reverse = ops.ReverseV2([1]) >>> anti_diagonal_output = reverse(anti_diagonal_input) >>> print(anti_diagonal_output) [[0 1] [1 0]]