Differences with torch.Tensor.size

View Source On Gitee

torch.Tensor.size

torch.Tensor.size() -> Tensor

For more information, see torch.Tensor.size.

mindspore.Tensor.shape

mindspore.Tensor.shape

For more information, see mindspore.Tensor.shape.

Differences

PyTorch: The size() method returns the shape of the Tensor.

MindSpore: Functionally consistent, but mindspore.Tensor.shape is a property, not a method.

Code Example

# PyTorch
import torch

input = torch.randn(3, 4, 5)
print(input.size())
# torch.Size([3, 4, 5])

# MindSpore
import mindspore.ops as ops

input = ops.randn(3, 4, 5)
print(input.shape)
# (3, 4, 5)