megengine.functional.eye¶
- eye(N, M=None, *, dtype='float32', device=None)[源代码]¶
Returns a two-dimensional tensor with ones on the diagonal and zeros elsewhere.
- 参数
- 关键字参数
dtype (
Tensor.dtype
, optional) – output tesnor data type. IfNone
, the output tesnor data type must be the default floating-point data type.device (
Tensor.device
, optional) – device on which to place the created tensor.
参见
If you want to create a diagonal matrix, see
diag
.- 返回类型
- 返回
a tensor where all elements are equal to zero, except for the diagonal, whose values are equal to one.
实际案例
>>> F.eye(3) Tensor([[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]], device=xpux:0)
>>> F.eye(4, 6) Tensor([[1. 0. 0. 0. 0. 0.] [0. 1. 0. 0. 0. 0.] [0. 0. 1. 0. 0. 0.] [0. 0. 0. 1. 0. 0.]], device=xpux:0)