eye_like

dragon.eye_like(
  other,
  k=0,
  dtype='float32',
  **kwargs
)[source]

Return a tensor of identity matrix with shape as the other.

\[\text{out} \leftarrow \text{diag}(1, 1, ..., 1) \]

The rows and cols of matrix are hinted by the input tensor:

x = dragon.ones(2, 3)
print(dragon.eye_like(x))  # [[1., 0.], [0., 1.]]

The diagonal could be controlled by k:

  • k > 0: Populate upper diagonal
  • k = 0: Populate main diagonal
  • k < 0: Populate lower diagonal
Parameters:
  • other (dragon.Tensor) – The tensor to hint the shape.
  • k (int, optional, default=0) – The index of diagonal.
  • dtype (str, optional, default='float32') – The optional data type.
Returns:

dragon.Tensor – The output tensor.