Sunday 15 September 2013

python - Get array index positions based on conditional -


I have a large numpy array and I want to get array index based on a given criteria. Nampee offers this but gives a boolean array:

  & gt; & Gt; & Gt; Np & gt; & Gt; & Gt; A = NP. Contrary to ([1, 2, 3, 4, 1, 2, 3]> gt;> B = 1 == 3> gt; & gt; B array ([false, false, true, false, false, false , True])   

But I really want to consider the actual index position as an integer, this is a simple way to do this:

  and Gt; & gt; c = np.arange (len (b)) gt; & gt; c = c [b] >> gt; & gt; Se Array ([2,6])   

In other words, is there a way to do that make the top of the ground?

I would like to go for: < Import as np a = np.array ([1, 2, 3, 4, 1, 2, 3]) index, = Np.where (a == 3) print index # [2] 6]

N-Amm allows arrays to deal with easy error (i.e., if there will be an exception to open multiple items) and it does not need to be flat

No comments:

Post a Comment