多维索引与numpy

时间:2018-04-13 17:46:41

标签: python numpy numpy-indexing

说我有以下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]])

感谢任何帮助或提示!

0 个答案:

没有答案