broadcasting-able
从最后一个维度开始匹配,所匹配得对象维度为1或者相同才能进行扩张。
a = [4,32,14,14]
b = [1,32,1,1]---[4,32,14,14]
b = [14,14]---[1,1,14,14]---[4,32,14,14]
错误
b = [2,32,14,14]
合并
cat
a.shape() = [4,32,8]
b.shape() = [5,32,8]
torch.cat([a,b],dim = 0).shape() = [9,32,8] dim 是指所拼接的维度
stack 创造新的维度
a.shape() = [32,8]
b.shape() = [32,8]
torch.stack([a,b],dim = 0).shape() = [2,32,8] a与b的维度必须完全一致
拆分
a.shape() = [6,32,8]
a.split([3,1,2], dim = 0).shape() = [3,32,8] [1,32,8] [2,32,8]
a.split(3,dim=0) = [3,32,8] [3,32,8]
a.chunk(2,dim=0) = [2,32,8] [2,32,8] [2,32,8]