[SciPy-User] extracting row from 2D array
Dan Lussier
dtlussier@gmail....
Wed Sep 29 12:05:15 CDT 2010
I want to extract a row from an 2D array given a criteria that is
based on each entry in that row.
By way of an example:
xyz = np.array([[ 159.278 , 14.7733 , 11.6785 ],
[ 158.251 , 1.11666, 4.76546],
[ 21.1418 , 84.8988 , 56.5169 ],
[ 154.149 , 4.9442 , 131.672 ],
[ 31.578 , 11.1078 , 8.47435]])
magnitude_sq = xyz*xyz.sum(axis=1)
I want to pull out the rows that satisfy a condition per row like
magnitude_sq < 16. I've found and tried np.extract, np.take and
np.compress. While np.extract fails to do what I want given that it
effectively wants to treat the 2D array was a 1D vector, I moved onto
np.compress and can get what I want via:
np.compress( magnitude_sq < 16 , xyz, axis=0)
What I'm trying to understand is the relationship between these
different functions (i.e. which one(s) are more fundamental) as the
documentation doesn't really identify how they might relate to each
other.
I have also posted the question to
http://ask.scipy.org/en/topic/50-extracting-entries-from-2d-numpy-array
to give that system at try.
More information about the SciPy-User
mailing list