Issue
What's the difference between torch.cat
and torch.stack
?
OpenAI's REINFORCE and actor-critic examples for reinforcement learning have the following:
# REINFORCE:
policy_loss = torch.cat(policy_loss).sum()
# actor-critic:
loss = torch.stack(policy_losses).sum() + torch.stack(value_losses).sum()
Solution
Concatenates sequence of tensors along a new dimension.
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)torch.stack([A, B], dim=0)
will be of shape (2, 3, 4)
Answered By - Jatentaki
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.