How to use torch.stack function

后端 未结 3 556
情深已故
情深已故 2021-02-07 06:49

I have a question about torch.stack

I have 2 tensors, a.shape=(2, 3, 4) and b.shape=(2, 3). How to stack them without in-place operation?

3条回答
  •  萌比男神i
    2021-02-07 07:32

    suppose you have two tensors a, b which are equal in dimensions i.e a ( A, B, C) so b (A, B , C) an example

    a=torch.randn(2,3,4)
    b=torch.randn(2,3,4)
    print(a.size())  # 2, 3, 4
    print(b.size()) # 2, 3, 4
    
    f=torch.stack([a, b], dim=2)  # 2, 3, 2, 4
    f
    

    it wont act if they wouldn't be the same dim. Be careful!!

提交回复
热议问题