2

假设我有以下 numpy 数组:

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]])

我想根据来自fp的值ix逐行提取值。上面的预期结果数组将是:

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

任何帮助或提示表示赞赏!

4

0 回答 0