[Numpy-discussion] conditional array indexing
Paul F. Dubois
paul at pfdubois.com
Mon Jan 28 13:21:02 CST 2002
import Numeric, sys
a = Numeric.array([1,2,1,2,4,3,1,2,3,2,3,2])
b = Numeric.array([4,3,5,2,4,5,3,6,3,2,5,6])
c = Numeric.arange(len(b))
print c[Numeric.argmin(Numeric.where(a==1, b, sys.maxint))]
From: numpy-discussion-admin at lists.sourceforge.net
[mailto:numpy-discussion-admin at lists.sourceforge.net] On Behalf Of
Sent: Monday, January 28, 2002 12:59 PM
To: numpy-discussion at lists.sourceforge.net
Subject: [Numpy-discussion] conditional array indexing
Very new user to Numpy, so excuse the question. It relates to a
issue which I have having trouble getting a grip on.
Specifically, say I have the following:
a = ([1,2,1,2,4,3,1,2,3,2,3,2])
b = ([4,3,5,2,4,5,3,6,3,2,5,6])
c = random variable of length=len(b)
I would like to get the value of C associated with the lowest value of b
within groupings of a. That is, there are three incidents of "1" in the
array. The lowest value of b associated with the value 1 in the a index
"3". This occurs in index value 6 on the a and b arrays. Now, I would
to then know the value of c.
Obviously the real problem is far more complex with len(a)==5000.
Thanks in advance.
Numpy-discussion mailing list Numpy-discussion at lists.sourceforge.net
More information about the Numpy-discussion