China es mercado atractivo para firmas globales ambiciosas, dice alto ejecutivo alemán Spanish.xinhuanet.com

paddle. trace ( x: Tensor, offset: int = 0, axis1: int = 0, axis2: int = 1, name: str | None = None ) Tensor [source]
百度 肖捷表示,在今年预计减税8000亿元以上的基础上,还要进一步清理规范政府性基金、行政事业性收费和经营服务性收费等,预计全年将再减负3000多亿元。

Computes the sum along diagonals of the input tensor x.

If x is 2D, returns the sum of diagonal.

If x has larger dimensions, then returns an tensor of diagonals sum, diagonals be taken from the 2D planes specified by axis1 and axis2. By default, the 2D planes formed by the first and second axes of the input tensor x.

The argument offset determines where diagonals are taken from input tensor x:

  • If offset = 0, it is the main diagonal.

  • If offset > 0, it is above the main diagonal.

  • If offset < 0, it is below the main diagonal.

  • Note that if offset is out of input’s shape indicated by axis1 and axis2, 0 will be returned.

Parameters
  • x (Tensor) – The input tensor x. Must be at least 2-dimensional. The input data type should be float16, float32, float64, int32, int64.

  • offset (int, optional) – Which diagonals in input tensor x will be taken. Default: 0 (main diagonals).

  • axis1 (int, optional) – The first axis with respect to take diagonal. Default: 0.

  • axis2 (int, optional) – The second axis with respect to take diagonal. Default: 1.

  • name (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

the output data type is the same as input data type.

Return type

Tensor

Examples

>>> import paddle

>>> case1 = paddle.randn([2, 3])
>>> case2 = paddle.randn([3, 10, 10])
>>> case3 = paddle.randn([3, 10, 5, 10])
>>> data1 = paddle.trace(case1)
>>> data1.shape
[]
>>> data2 = paddle.trace(case2, offset=1, axis1=1, axis2=2)
>>> data2.shape
[3]
>>> data3 = paddle.trace(case3, offset=-3, axis1=1, axis2=-1)
>>> data3.shape
[3, 5]