mindspore.Tensor.sum_to_size
- Tensor.sum_to_size(*size)[source]
Sum self Tensor to the size. size must be expandable to the Tensor size.
- Parameters
size (Union[tuple(int), int]) – The expected shape of output Tensor.
- Returns
Tensor, the sum result of self Tensor according to the size.
- Raises
ValueError – If size is not expandable to the size of self Tensor.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> import mindspore >>> from mindspore import Tensor >>> x = Tensor(np.random.randn(3, 3, 3, 3, 3, 3), mindspore.float32) >>> output = x.sum_to_size((1, 3, 1, 3)) >>> print(output.shape) (1, 3, 1, 3)