'How to get multiple coordinates from 2d array in NumPy

I have a matrix A, and a (list of tuples) corresponding to coordinates C. How do I get A[C]?

For example:

>>> A
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]])
>>> C
[(0,0), (1,2), (4,-1)]

The function I want, but don't know the name of, works like this:

>>> func(A,C)
[0, 7, 24]

Does such a function (or some funky NumPy indexing syntax) exist, or is a for loop the only way to get this result?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source