In both MATLAB and Numpy, arrays can be indexed by arrays. However, the behavior is different. Let me explain this by an example.
MATLAB:
>> A = rand(5,5)
A =
0.1622 0.6020 0.4505 0.8258 0.1067
0.7943 0.2630 0.0838 0.5383 0.9619
0.3112 0.6541 0.2290 0.9961 0.0046
0.5285 0.6892 0.9133 0.0782 0.7749
0.1656 0.7482 0.1524 0.4427 0.8173
>> A([1,3,5],[1,3,5])
ans =
0.1622 0.4505 0.1067
0.3112 0.2290 0.0046
0.1656 0.1524 0.8173
Numpy:
In [2]: A = arange(25).reshape((5,5))
In [3]: A
Out[3]:
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]])
In [6]: A[[0,2,4], [0,2,4]]
Out[6]: array([ 0, 12, 24])
In words: MATLAB selects rows and columns, Numpy "zips" the two index arrays and uses the tuples to point to entries.
How can I get the MATLAB behavior with Numpy?