Function Differences with torch.Tensor.sum
torch.Tensor.sum
torch.Tensor.sum(dim=None, keepdim=False, dtype=None)
For more information, see torch.Tensor.sum.
mindspore.Tensor.sum
mindspore.Tensor.sum(axis=None, dtype=None, keepdims=False, initial=None)
For more information, see mindspore.Tensor.sum.
Usage
The basic function is the same. mindspore.Tensor.sum can be configured with the input parameter initial to set the starting value of the summation, and the other input parameters are the same for both interfaces.
Code Example
import mindspore as ms
a = ms.Tensor([10, -5], ms.float32)
print(a.sum())
# 5.0
print(a.sum(initial=2))
# 7.0
import torch
b = torch.Tensor([10, -5])
print(torch.Tensor.sum(b))
# tensor(5.)
