Pytorch:将张量指数增加到特定大小
Pytorch: Increase indice of tensor to specific size
我有一个张量 [20, 3, 32, 32]
我想将 3
增加到 64
([20,64,32,32]
,其中 20
是批量大小)。我尝试了重复功能。但这只会给我 63
或 66
,因为重复只能平铺(乘以)索引。
我该如何解决这个问题?
谢谢!
您可以重复使用 torch.repeat
,然后使用索引进行过滤。
t = torch.rand(20,3,32,32)
t.shape
torch.Size([20, 3, 32, 32])
t = t.repeat(1,22,1,1)[:,:-2,:,:]
t.shape
torch.Size([20, 64, 32, 32])
我有一个张量 [20, 3, 32, 32]
我想将 3
增加到 64
([20,64,32,32]
,其中 20
是批量大小)。我尝试了重复功能。但这只会给我 63
或 66
,因为重复只能平铺(乘以)索引。
我该如何解决这个问题?
谢谢!
您可以重复使用 torch.repeat
,然后使用索引进行过滤。
t = torch.rand(20,3,32,32)
t.shape
torch.Size([20, 3, 32, 32])
t = t.repeat(1,22,1,1)[:,:-2,:,:]
t.shape
torch.Size([20, 64, 32, 32])