请看下面一个很普通的PyTorch向量:
import torch
input = torch.ones(3, 5)
print(input)
dim = len(input.shape)
print(dim)
对于上面的2维input向量,它有两个维度,分别表示为0维和1维。input向量的外形轮廓是这样的:
tensor([[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.]])
通过外形来看,我们可以知道最外面的中括号为1维,其次为2维。
简单的说,从左向右,给中括号标记索引,即是向量维度的计数。
从俯瞰的角度来看,input向量长这个样子:

从dim=0的角度(横向角度)来看,input向量长这个样子:

从dim=1的角度(纵向角度)来看,input向量长这个样子:
