定义
torch.cat((a,b),dim)
用法
操作后不会增加维度数量,但会增加维度值。在dim维度上对a和b进行拼接
示例
import torch
a = torch.tensor([[1,2,3],[4,5,6],[7,8,9]])
b = torch.tensor([[11,22,33],[44,55,66],[77,88,99]])
print(a)
print(b)
>>tensor([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
tensor([[11, 22, 33],
[44, 55, 66],
[77, 88, 99]])
在dim=0上拼接a和b
torch.cat((a,b),dim=0)
>> tensor([[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[11, 22, 33],
[44, 55, 66],
[77, 88, 99]])
在dim=1上拼接a和b
torch.cat((a,b),dim=1)
>>tensor([[ 1, 2, 3, 11, 22, 33],
[ 4, 5, 6, 44, 55, 66],
[ 7, 8, 9, 77, 88, 99]])