当前位置:网站首页>torch.cat()用法

torch.cat()用法

2022-08-11 05:35:00 Pr4da

torch.cat()可以对tensor进行上下或左右拼接,其传入的参数为:

torch.cat(tensors, dim=0)

dim控制拼接的维度,dim=0为上下拼接,dim=1为左右拼接1
下面是实例详解:

>>> import torch
>>> a = torch.rand((2,3))
>>> a
tensor([[0.7515, 0.1021, 0.0726],
        [0.0575, 0.1666, 0.2763]])
>>> b = torch.rand((2,3))
>>> b
tensor([[0.7485, 0.8340, 0.2617],
        [0.7847, 0.2847, 0.3445]])
>>> c =torch.cat((a,b),dim=0)
>>> c
tensor([[0.7515, 0.1021, 0.0726],
        [0.0575, 0.1666, 0.2763],
        [0.7485, 0.8340, 0.2617],
        [0.7847, 0.2847, 0.3445]])
>>> d = torch.cat((a,b),dim=1)
>>> d
tensor([[0.7515, 0.1021, 0.0726, 0.7485, 0.8340, 0.2617],
        [0.0575, 0.1666, 0.2763, 0.7847, 0.2847, 0.3445]])

  1. torch.cat()官方文档

原网站

版权声明
本文为[Pr4da]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_40210586/article/details/115165770