[SciPy-user] really basic where() function question

Michael Hearne mhearne at usgs.gov
Mon Aug 27 23:23:29 EDT 2007


I'm trying to put together a presentation at work on Python, and I'm  
confused about the where() numpy function.

The documentation, which is scant, indicates that where() requires  
three input arguments:

where(condition,x,y) returns an array shaped like condition and has  
elements of x and y where condition is respectively true or false

First, I have to admit that I don't understand what x and y are for  
here.

Second, I want to use where() like find() in Matlab - namely:
a = array([3,5,7,9])
i = where(a <= 6) => should return (array([0, 1]),) (see http:// 
www.scipy.org/ 
Numpy_Example_List#head-7de97cb88f064612d2f339e9713a949cd7f2f804)

instead, I get this error:
------------------------------------------------------------------------ 
---
<type 'exceptions.TypeError'>             Traceback (most recent call  
last)

/Users/mhearne/scipy/<ipython console> in <module>()

<type 'exceptions.TypeError'>: where() takes exactly 3 arguments (1  
given)

What am I doing wrong?  Or did the usage of where() change since the  
cookbook example was written?

--Mike

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20070827/bf2f3671/attachment.html>


More information about the SciPy-User mailing list