apgsov
apgsov

Reputation: 904

Reshaping or "concatenating" a tensor along an axis

I have a tensor, t, of the following shape: torch.Size([280, 4, 768]).

What I want is to achieve, effectively, concatenation along the second axis, resulting in torch.Size([280, 3072]).

I know that I can for instance, do:

torch.cat((x[:, -4, :], x[:, -3, :], x[:, -2, :], x[:, -1, :]), dim=1)

but is there a nicer way of writing this?

How do I achieve reshaping along the second axis without messing up my values?

Upvotes: 1

Views: 1682

Answers (1)

Ivan
Ivan

Reputation: 40618

Yes you can apply a straight forward reshape:

>>> x.reshape(len(x), -1)

Upvotes: 3

Related Questions