torch.cat()使用

百度一下发现   网上给的列子 也太low了=  =

自己写了个  省得忘了

batch_size=3
x = torch.randn(batch_size).unsqueeze(1)
result_0=torch.cat([x**i for i in range(1,4)],0)
result_1=torch.cat([x**i for i in range(1,4)],1)
print(result_0.size())
print(result_1.size())

结果为:

torch.Size([9, 1])
torch.Size([3, 3])

也可以把 .size() 去掉看结果 就懂了

print(result_0)

print(result_1)

大概意思就是  0 的时候   类似这样 一个一个的:

tensor([[-0.8996],
        [-0.7313],
        [ 1.3803],
        [ 0.8093],
        [ 0.5348],
        [ 1.9053],
        [-0.7280],
        [-0.3911],
        [ 2.6299]])
 

1的时候  :

tensor([[-0.8996,  0.8093, -0.7280],
        [-0.7313,  0.5348, -0.3911],
        [ 1.3803,  1.9053,  2.6299]])

扫描二维码关注公众号,回复: 4329212 查看本文章

猜你喜欢

转载自blog.csdn.net/bc521bc/article/details/84702626