import torch from torch.nn import functional as F x = torch.Tensor([ [[0,1,2,3,4], [5,6,7,8,9]], [[10,11,12,13,14], [15,16,17,18,19]], [[20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], ]) print(x.size()) print(x.flatten(1)==x.reshape(3,-1))
输出:
torch.Size([3, 2, 5])
tensor([[True, True, True, True, True, True, True, True, True, True],
[True, True, True, True, True, True, True, True, True, True],
[True, True, True, True, True, True, True, True, True, True]])