Kevin4720
Kevin4720

Reputation: 111

pytorch question about tensor shape. And how to reshape a tensor

When I do print("action shape:, ", action.shape) for my tensor action I got (64,). It is the same as (1, 64)? And how do I reshape its size to (64,1)?

Upvotes: 0

Views: 44

Answers (1)

Dwight Foster
Dwight Foster

Reputation: 352

Technically it is not the same shape and in pytorch you will get an error if you have things that need a shape of (64,) but you give it (1,64) but it is easy to change it to (64,) by squeezing it. To reshape it to a size of (64, 1) you can do this

action = action.unsqueeze(1)
# or
action = action.view(-1, 1)

either will work but I would recommend the first one.

Upvotes: 2

Related Questions