import torch
conf_data=torch.tensor([[[1, 2,3], [4,5,6]], [[7,8,9],[10,11,12]],[[10, 20,30], [40,50,60]], [[70,80,90],[100,110,120]]])
conf_t=torch.tensor([1,2,3,4])
conf_data = conf_data.view(-1, 3)
conf_t = conf_t.view(-1)
print(conf_data)
print(conf_t)
结果:
tensor([[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[ 10, 11, 12],
[ 10, 20, 30],
[ 40, 50, 60],
[ 70, 80, 90],
[100, 110, 120]])
tensor([1, 2, 3, 4])