Search code examples
python-2.7numpyminimum

Truth error while trying to find all equal minimum values in array, then retrieve indices


I'm trying to find all the minimum values in an array and retrieve their indices.

import numpy as np
a = np.array([[1,2],[1,4]])
minE = np.min(a)
ax,ay = np.unravel_index(minE, a.shape)

only returns minE = 1, ax, ay = 0 1

Can anyone help me out in a way that would also provide indices for all equal value minima (here, indices for both 1's)?


Solution

  • Were you looking for this:

    x = np.array([[1,2,3],[1,4,2]])
    np.where(x == np.amin(x))