Skip to content Skip to sidebar Skip to footer

Index Multidimensional Array With Index Array

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, 10, 10) idx = [[1, 1, 2],

Solution 1:

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

a[tuple(np.transpose(idx))]

Post a Comment for "Index Multidimensional Array With Index Array"