I'm back with another numpy array question.
I have a 2D array:
A = np.array([[0,0,1,1,0,0,0],[0,1,1,0,1,0,0],[1,0,0,1,1,0,0]])
=
array([[0, 0, 1, 1, 0, 0, 0],
[0, 1, 1, 0, 1, 0, 0],
[1, 0, 0, 1, 1, 0, 0]])
and an array of shifts
shifts = np.array([2,4,1])
=
array([2, 4, 1])
Is there a way I can do the equivalent of np.roll(A,shifts) and it will roll A[0,:] by shifts[0], and so forth?
For clarification, I want to do this without for loops, I have already implemented with for loops and now need to optimise the speed (I am in reality working with much larger arrays than those used in the example).