import torch
t1 = torch.tensor([[1,6,4],[3,4,5]])
#在第二列后插入一列与第二列一样
t1=t1[:,[0,1,1,2]]
t1[:,2]=0 #第三列为0
print(t1)
#---------显示为:------------
tensor([[1, 6, 0, 4],
[3, 4, 0, 5]])
import torch
t1 = torch.tensor([[1,6,4],[3,4,5]])
#在第二列后插入一列与第二列一样
t1=t1[:,[0,1,1,2]]
t1[:,2]=0 #第三列为0
print(t1)
#---------显示为:------------
tensor([[1, 6, 0, 4],
[3, 4, 0, 5]])