I’ve got a 2D numpy array, A containing an index into another array, B. What is a good way to get C from A and B using numpy?
A = array([[1, 1, 0, 2],
[1, 0, 0, 2],
[1, 1, 0, 2]])
B = array([0, 5, 3])
C = array([[5, 5, 0, 3],
[5, 0, 0, 3],
[5, 5, 0, 3]])
How about this
C = B[A]. That’s the beauty of numpy: