flat_indices = numpy.argpartition(arr.ravel(), n - 1)[:n]
row_indices, col_indices = numpy.unravel_index(flat_indices, arr.shape)
python+numpy: efficient way to take the min/max n values and indices from a matrix