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
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.