0
votes

Doing np.roll(a, 1, axis = 1) on:

a = np.array([  
             [6, 3, 9, 2, 3],
             [1, 7, 8, 1, 2],
             [5, 4, 2, 2, 4],
             [3, 9, 7, 6, 5],
            ])

results in the correct:

array([
       [3, 6, 3, 9, 2],
       [2, 1, 7, 8, 1],
       [4, 5, 4, 2, 2],
       [5, 3, 9, 7, 6]
     ])

The documentation says:

If a tuple, then axis must be a tuple of the same size, and each of the given axes is shifted by the corresponding number.

Now I like to roll rows of a by different values, like [1,2,1,3] meaning, first row will be rolled by 1, second by 2, third by 1 and forth by 3. But np.roll(a, [1,2,1,3], axis=(1,1,1,1)) doesn't seem to do it. What would be the correct interpretation of the sentence in the docs?

This is doing what the docs say it will. Shift axis 1 by 1, then shift axis 1 by 2, etc. which is equivalent to np.roll(a, 7, axis = 1). See this thread for other options. - Mark