[torch 参数更多]torch.Tensor.size

torch.Tensor.size

torch.Tensor.size(dim=None)

paddle.Tensor.shape

paddle.Tensor.shape

其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下:

参数映射

| PyTorch | PaddlePaddle | 备注 | | ——- | ———— | ——- | | dim | - | 表示获取大小的轴,Paddle 无此参数,需要进行转写。 |

转写示例

# Pytorch 写法
torch.tensor([-1, -2, 3]).size(0)

# Paddle 写法
paddle.to_tensor([-0.4, -0.2, 0.1, 0.3]).shape[0]