I have two arrays, one is a matrix of index pairs,
a = array([[[0,0],[1,1]],[[2,0],[2,1]]], dtype=int)
and another which is a data matrix for accessing these indices
b = array([[1,2,3],[4,5,6],[7,8,9]])
and I want to use indices a to get b entries. Simply:
>>> b[a]
doesn't work, as it gives one row from b for each entry in a , i.e.
array([[[[1,2,3], [1,2,3]], [[4,5,6], [4,5,6]]], [[[7,8,9], [1,2,3]], [[7,8,9], [4,5,6]]]])
when I would like to use an index pair on the last axis a to give two indices b :
array([[1,5],[7,8]])
Is there a clean way to do this, or do I need to change the form of b and combine the columns of a accordingly?
In my real problem, a has about 5 million records, and b 100 per 100, I would like to avoid loops.