find index of equal values in an array
<p>So I have an array that I read from a file with several numbers. I need to find all the indices of the array equal to a certain value, and I do it in a loop (it's different values each time). It works perfect if I do it one by one, but when I do the loop, I get 0 matches in some cases, and I know the answer shouldn't be zero. It's a long array, but this is the example:</p>

<pre><code>array = [0.2  0.2  0.4  .... 1.0]
m=20
for i in xrange(mbins):
    mg = 0.2*i
    for j in xrange(iterations):
        w = np.where(list == mg)
        print w
</code></pre>

<p>But I get w empty for i = 3,4,7, and some other numbers. I really don't understand what's going on. I tried without np.where, but still doesn't work.</p>

<p>(the real code is a bit more complicated than this, but this is where it fails)</p>

<p>Thanks!</p>

<p>Is this what you want, getting all indices of a value from a list through iteration:</p>

<pre><code>mg = # some value
start = lst.index(mg)
# first occurrence of mg
print (start)
for i in range(lst.count(mg)-1):
  start += lst[start+1:].index(mg)+1
  print (start)
</code></pre>

<p>This will return all indices of <code>mg</code> in <code>lst</code>.</p>

python