# [SciPy-user] How to use where

Dave dave.hirschfeld@gmail....
Thu Aug 21 09:03:21 CDT 2008

```Alexander Borghgraef <alexander.borghgraef.rma <at> gmail.com> writes:

>
> 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 )
>

In [1]: listofvectors = rand(100,2)

In [2]: bound = array([0.5,0.8])

In [3]: idx = all(listofvectors  < bounds,axis=1)

In [4]: inbounds = listofvectors[idx,:]

I'm not sure of the utility of where - I tend to use boolean masks. Is there any
reason one wouldn't use the code I posted above?

-Dave

```