简体   繁体   English

如何在pytorch中扩展张量的尺寸

[英]how to expand the dimensions of a tensor in pytorch

i'm a newcomer for pytorch.我是 pytorch 的新手。 if i have a tensor like that:如果我有这样的张量:

A = torch.tensor([[1, 2, 3], [ 4, 5, 6]]) , A = torch.tensor([[1, 2, 3], [ 4, 5, 6]]) ,

but my question is how to get a 2 dimensions tensor like:但我的问题是如何获得二维张量,如:

B =  Tensor([[[1, 2, 3],
                           [4, 5, 6]], 

                          [[1, 2, 3], 
                           [4, 5, 6]]])

You can concatenate ...你可以串联...

A
tensor([[[1., 2., 3.],
         [4., 5., 6.]]])
B = torch.cat((a, a))

B
tensor([[[1., 2., 3.],
         [4., 5., 6.]],

        [[1., 2., 3.],
         [4., 5., 6.]]])

只需像这样使用重复功能

B = A.repeat(2, 1, 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM