2

Say I have the following numpy arrays:

import numpy as np

np.random.seed(100)

fp = np.random.rand(4000, 5)
ix = np.random.randint(0, 5, (3, 3))

fp
array([[ 0.54340494,  0.27836939,  0.42451759,  0.84477613,  0.00471886],
       [ 0.12156912,  0.67074908,  0.82585276,  0.13670659,  0.57509333],
       [ 0.89132195,  0.20920212,  0.18532822,  0.10837689,  0.21969749]])

ix
array([[3, 4, 4],
       [1, 3, 4],
       [4, 3, 3]])

I would like to extract the values from fp based on the values from ix, row by row. The expected resulting array from the above would be:

array([[ 0.84477613,  0.00471886,  0.00471886],
       [ 0.67074908,  0.13670659,  0.57509333],
       [ 0.21969749,  0.10837689,  0.10837689]])

Any help or hint is appreciated!

Eric B
  • 1,635
  • 4
  • 13
  • 27

0 Answers0