So I was experimenting with numpy and I ran across a strange (?) behavior in the rollaxis method.
In [81]: a = np.ones((4, 3, 2))
In [82]: a.shape
Out[82]: (4, 3, 2)
In [83]: x = np.rollaxis(a, 2)
In [84]: x.shape
Out[84]: (2, 4, 3)
In [85]: np.rollaxis(x, -2).shape
Out[85]: (4, 2, 3)
Shouldn't the -2 reverse the rollaxis? What I'm trying to do is apply a matrix that can only be applied when the 2 coordinate is first. But then I want to put my array back into its original form. The only things which I have found to work are applying np.rollaxis(x, 2)
twice, or applying np.rollaxis(x, 0, start=3)
. I just found these by guessing and I have no idea why they work. They also seem to be obscuring what I'm really trying to do. Could somebody please explain the way that I should 'reverse' a roll, or what I'm doing wrong?
(Is there a pythonic way to do this?)