mindspore.ops.Trace
- class mindspore.ops.Trace[source]
Returns a new tensor that is the sum of the input trace.
Note
Input must be matrix, and complex number is not supported at present.
- Inputs:
x (Tensor) - A matrix to be calculated. The matrix must be two dimensional.
- Outputs:
Tensor, with the same data type as input x, and size equals to 1.
- Raises
TypeError – If x is not a Tensor.
ValueError – If the dimension of x is not equal to 2.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> x = Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), mindspore.float32) >>> trace = ops.Trace() >>> output = trace(x) >>> print(output) 15.