How to (effectively) do the following:
x = np.arange(49) x2 = np.reshape(x, (7,7)) x2 array([[ 0, 1, 2, 3, 4, 5, 6], [ 7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, 32, 33, 34], [35, 36, 37, 38, 39, 40, 41], [42, 43, 44, 45, 46, 47, 48]])
From here I want to drop a couple of things. I want to drop 0,7,14,21 etc., so 14 will return. Then the same thing with 4,11,18,25, etc., 39 - up.
The result should be:
x2 array([[14, 1, 2, 3, 39, 5, 6], [21, 8, 9, 10, 46, 12, 13], [28, 15, 16, 17, 4, 19, 20], [35, 22, 23, 24, 11, 26, 27], [42, 29, 30, 31, 18, 33, 34], [ 0, 36, 37, 38, 25, 40, 41], [ 7, 43, 44, 45, 32, 47, 48]])
I looked at numpy.roll, here and google, but could not find how to do this.
For horizontal rolls, I could:
np.roll(x2[0], 3, axis=0) x3 array([4, 5, 6, 0, 1, 2, 3])
But how do I return a full array with this roll change as a new copy?