I have a problem using numpy fancy indexing which I somehow can't get my head around. I know, that I can get an array of submatrices of rows like this:
A = np.array([[1,2,3],[4,5,6],[7,8,9]])
B = A[np.array([[0,1],[1,2]])]
This gives:
array([[[1, 2, 3],
[4, 5, 6]],
[[4, 5, 6],
[7, 8, 9]]])
a threedimensional numpy array containing matrices comprising the first,second row and second,third row of A, respectively. What I want is now basically the same operation for the cols of A which should give
array([[[1, 2],
[4, 5],
[7, 8]],
[[2, 3],
[5, 6],
[8, 9]]])
But
B = A[:,np.array([[0,1],[1,2]])]
does not work (probably because of the order of the index evaluations). It gives
array([[[1, 2],
[2, 3]],
[[4, 5],
[5, 6]],
[[7, 8],
[8, 9]]])
How can I accomplish this in the best way? Should I work with transposed matrices?