pytorch张量的形状

  1. 标量的形状是[]
  2. 向量的形状是[N],N是向量元素的个数
  3. 二维表格的形状是(M,N),M是行数,N是列数
  4. 三维矩阵的形状是(M,N,C),M是长,N是宽,C是高
>>> 
>>> import torch as th
>>> 
>>> th.tensor(2)
tensor(2)
>>> th.tensor([2])
tensor([2])
>>> th.tensor([[2]])
tensor([[2]])
>>> th.tensor([[[2]]])
tensor([[[2]]])
>>> 
>>> th.tensor(2).shape
torch.Size([])
>>> th.tensor([2]).shape
torch.Size([1])
>>> th.tensor([[2]]).shape
torch.Size([1, 1])
>>> th.tensor([[[2]]]).shape
torch.Size([1, 1, 1])
>>> 
>>> 

猜你喜欢

转载自blog.csdn.net/xiaolixi199311/article/details/140210091