Reputation: 4558
numpy.rollaxis
rolls the axis backwards. Suppose I have an ndarray
with the shape (3,640,480)
and I want to roll the first axis to the last, changing the shape to (640,480,3)
. Can I do this easily? Although in this simple case two calls of numpy.rollaxis
will work, if I have n axis this will be clumsy.
Upvotes: 3
Views: 641
Reputation: 10298
There is an optional third argument, start
, which tells where the axis should end up. In this case, you want to move axis 0
before axis 3
:
>>> x.shape
(3,640,480)
>>> x2 = np.rollaxis(a,0,3)
>>> x2.shape
(640,480,3)
Upvotes: 4