Index multidimensional array with index array

前端 未结 1 755
無奈伤痛
無奈伤痛 2020-12-21 13:56

I have an array of index tuples and I would like to use it to pick out values from a multidimensional numpy array,

import numpy
a = numpy.random.rand(10, 1         


        
相关标签:
1条回答
  • 2020-12-21 14:25

    You could convert the transposed version of idx to a tuple and then index for a vectorized solution -

    a[tuple(np.transpose(idx))]
    
    0 讨论(0)
提交回复
热议问题