[SciPy-user] How to use where

Alexander Borghgraef alexander.borghgraef.rma@gmail....
Thu Aug 21 04:41:20 CDT 2008


Hi all,

 I'm trying to figure out here how 'where' works exactly. I'm working
on a list of vectors which I represent as a 2D array, and I'd like to
remove the vectors which are out of bounds. So after some
experimenting I got to basically this:

 listofvectors = ...
       # shape is ( 100, 2 )
 bound = array( [ xmax, ymax ] )
 inside = where( all( listofvectors < bound, axis = 1 ) )    # inside
is ( array[ 1, 2, 4, 10, ... ] )
 listofvectors = listofvectors[ inside, : ]
# shape is ( 1, 100, 2 )

Ok, so I'm almost there. The change of shape is annoying, since I'll
be using listofvectors in a loop to sample from an image. Not that I
can't work around this, but I'm looking for a cleaner way. Also, I
don't really get why numpy is doing this, anyone care to explain?
Thanks.

-- 
Alex Borghgraef


More information about the SciPy-user mailing list