np.argmax on multidimensional arrays, keeping some indexes fixed
问题 I have a collection of 2D narrays, depending on two integer indexes, say p1 and p2, with each matrix of the same shape. Then I need to find, for each pair (p1,p2), the maximum value of the matrix and the indexes of these maxima. A trivial, albeit slow, way to do this would would be to do something like this import numpy as np import itertools range1=range(1,10) range2=range(1,20) for p1,p2 in itertools.product(range1,range1): mat=np.random.rand(10,10) index=np.unravel_index(mat.argmax(), mat