1. torch.tensor中的拼接
我发现torch中stack没有list的append快。但是从一个大的嵌套的tensor中拿出几个重新组成一个新的tensor,可以用如下代码。不能直接append。
poly_1 = torch.ones([3,5])
poly_2 = torch.zeros([2,5])
node_attr = torch.cat([poly_1, poly_2], dim=0)
tmp_attr = node_attr.unsqueeze_(1)
edge_attr = []
for i in range(2):
edge_attr.append(tmp_attr[i])
edge_attr = torch.cat(edge_attr, dim=0)
2. flatten() , reshape()搭配使用
np.rollaxis().reshape()