mindspore.ops.trace
- mindspore.ops.trace(input)[source]
Return the sum of the elements along the diagonal of the input tensor.
Note
Input must be matrix, and complex number is not supported at present.
- Parameters
input (Tensor) – The input tensor.
- Returns
Tensor
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> input = mindspore.tensor([[0, 1, 2], ... [3, 4, 5], ... [6, 7, 8]]) >>> mindspore.ops.trace(input) Tensor(shape=[], dtype=Int64, value= 12)