代码拉取完成,页面将自动刷新
trace:
description: |
Returns a new tensor that is the sum of the `input` main trace.
Note:
Input must be matrix, and complex number is not supported at present.
Args:
input (Tensor): A matrix to be calculated. The matrix must be two dimensional.
Returns:
Tensor, with the same data type as input `input`, and size equals to 1.
Raises:
TypeError: If `input` is not a Tensor.
ValueError: If the dimension of `input` is not equal to 2.
Supported Platforms:
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> input = Tensor(np.array([[10, 11, 12], [13, 14, 15], [16, 17, 18]]), mindspore.float32)
>>> output = ops.trace(input)
>>> print(output)
42.0
>>> input = Tensor(np.arange(1, 13).reshape(3, 4), mindspore.float32)
>>> output = ops.trace(input)
>>> print(output)
18.0
>>> input = Tensor(np.arange(12, 0, -1).reshape(4, 3), mindspore.float32)
>>> output = ops.trace(input)
>>> print(output)
24.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。