1. Tensor
1.1 类型转换
1.1.1 类型转换h5.dataset转Tensor
先转化成np数组,再转换成tensor
lbl = torch.tensor(np.array(lbl))
1.2 拼接Tensor
1.2.1 torch.cat和torch.stack
torch.cat(seq,dim=0,out=None)
torch.stack(seq, dim=0, out=None)
相同点:
- 沿着dim连接seq中的tensor, 所有的tensor必须有相同的size或为empty
# a:[1,2,3]
# b:[2,3,4]
torch.cat((a,b))
# [1,2,3,2,3,4]
# a:[1,2,3]
# b:[2,3,4]
torch.stack((a,b))
# [[1,2,3][2,3,4]]