- tensor.emptyで空のtensorを作れます。
空のtensorでもshapeをもちます。
q0 = torch.empty(1,0)
print(q0)
q0 = torch.empty(1,0,2,3)
print(q0)
- 以下のようにappendできます。
q0 = torch.empty(0) #.unsqueeze(0)
qr = torch.tensor([-1,-2,-3,-4])#.unsqueeze(0)
qt = torch.tensor([1,2,3]) #.unsqueeze(0)
qrr= torch.cat((q0,qr,qt),dim=0)
#qrr= torch.cat((q0,qr,qt),dim=1).squeeze(0)
print(q0)
print(qr)
print(qrr)
print(qr.shape,qt.shape,qrr.shape)
#連続的につなぐ。これで速度が出るのかどうか
qt=torch.cat(tuple(qt for _ in range(3)))
print(qt)
torch.catは配列(m,n,n1)と配列(m,n,n2)をつなげて配列(m,n,n1+n2)を作れる。