I have an application where I need to reverse the elements along one axis of a NumPy array according to some stride. As an example, let's consider that I have the following array
In [1]: import numpy as np
In [2]: a = np.array([[1,2],[3,4],[5,6],[7,8]])
In [3]: a
Out[3]:
array([[1, 2],
[3, 4],
[5, 6],
[7, 8]])
I want to reverse this array along the first axis (axis=0
) with a stride of 2. In other words, I want to quickly get the following array:
Out[4]:
array([[3, 4],
[1, 2],
[7, 8],
[5, 6]])
Is there a quick way to do this with a built-in NumPy routine?