What's the difference between torch.stack() and torch.cat() functions?

后端 未结 1 1147
傲寒
傲寒 2020-12-08 13:24

OpenAI\'s REINFORCE and actor-critic example for reinforcement learning has the following code:

REINFORCE:

policy_loss = torch.cat(policy_loss).sum()         


        
相关标签:
1条回答
  • 2020-12-08 13:25

    stack

    Concatenates sequence of tensors along a new dimension.

    cat

    Concatenates the given sequence of seq tensors in the given dimension.

    So if A and B are of shape (3, 4), torch.cat([A, B], dim=0) will be of shape (6, 4) and torch.stack([A, B], dim=0) will be of shape (2, 3, 4).

    0 讨论(0)
提交回复
热议问题