eye¶
dragon.
eye
(
n,
m=None,
k=0,
dtype='float32',
**kwargs
)[source]¶Return a tensor constructed as the identity matrix.
\[\text{out} \leftarrow \text{diag}(1, 1, ..., 1) \]The rows and cols of matrix are determined by
n
andm
:print(dragon.eye(2)) # [[1., 0.], [0., 1.]] print(dragon.eye(2, 3)) # [[1., 0., 0.], [0., 1., 0.]]
The diagonal could be controlled by
k
:- k > 0: Populate upper diagonal
- k = 0: Populate main diagonal
- k < 0: Populate lower diagonal
- Parameters:
- n (int) – The number of output rows.
- m (int, optional) – The number of output cols.
- k (int, optional, default=0) – The index of diagonal.
- dtype (str, optional, default='float32') – The optional data type.
- Returns:
dragon.Tensor – The output tensor.