Pytorch-数据的拼接

数据的拼接

torch.cat(inputs, dimension=0) → Tensor
inputs:你要拼接的输入x,y,z;
dimension:0,为按照行拼接。1,为按照列拼接。
例子
将三维数据a,b,c组成图像的三通道数据。
import torch
"""
将三维数据a,b,c组成图像的三通道数据。
"""
a = torch.randn(1,180, 7)
print(a.shape)
b  = torch.randn(1,180, 7)
print(a.shape)
c  = torch.randn(1,180, 7)
print(c.shape)
c =torch.cat((a,b,c),0)
print(c.shape)

输出:

torch.Size([1, 180, 7])
torch.Size([1, 180, 7])
torch.Size([1, 180, 7])
torch.Size([3, 180, 7])

[1]https://pytorch-cn.readthedocs.io/zh/latest/package_references/torch/#tensors

猜你喜欢

转载自blog.csdn.net/qq_31244453/article/details/115161858