# 0维Tensor:也就是一个标量(Scalar),它没有维度,
# 1维Tensor:也称作向量(Vector),它有一个维度
# 2维Tensor:也称作矩阵(Matrix),它有两个维度
# 3维Tensor:也叫高维Tensor(>=3), 它有3个维度可以想象为一个数据立方体
import torch
x = torch.tensor(1)
print(x.shape, x.size(), x.dim())
x = torch.tensor([1])
print(x.shape, x.size(), x.dim())
x = torch.tensor([1, 2, 3])
print(x.shape, x.size(), x.dim())
x = torch.tensor([[1, 2, 3], [4, 5, 6]])
print(x.shape, x.size(), x.dim())
x = torch.tensor([[1]])
print(x.shape, x.size(), x.dim())
x = torch.tensor([[1, 2, 3]])
print(x.shape, x.size(), x.dim())
x = torch.tensor([[1], [1], [1]])
print(x.shape, x.size(), x.dim())
x = torch.tensor([[[1]]])
print(x.shape, x.size(), x.dim())
x = torch.tensor([[[1, 2, -1], [3, 4, -1]], [[5, 6, -1], [7, 8, -1]]])
print(x.shape, x.size(), x.dim())
'''
torch.Size([]) torch.Size([]) 0
torch.Size([1]) torch.Size([1]) 1
torch.Size([3]) torch.Size([3]) 1
torch.Size([2, 3]) torch.Size([2, 3]) 2
torch.Size([1, 1]) torch.Size([1, 1]) 2
torch.Size([1, 3]) torch.Size([1, 3]) 2
torch.Size([3, 1]) torch.Size([3, 1]) 2
torch.Size([1, 1, 1]) torch.Size([1, 1, 1]) 3
torch.Size([2, 2, 3]) torch.Size([2, 2, 3]) 3
'''
0条评论