[SciPy-user] where bug

Johannes Loehnert a.u.r.e.l.i.a.n at gmx.net
Tue Oct 10 01:36:47 CDT 2006


Am Dienstag, 10. Oktober 2006 08:26 schrieb Ryan Krauss:
> I am having a problem running some slightly older code under a fairly
> new Scipy for the first time.  The code uses where and something like
> this:
> In [23]: t=arange(0,1,0.01)
>
> In [24]: where(t>0.5)
> Out[24]:
> (array([51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
>        68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
>        85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]),)
>
> used to return just the array instead of the tuple with the array in
> it.  Is this a feature or a bug?  

Feature. If you use n-d arrays, you will get back a tuple of size n, one index 
array for each axis. You ran into the special case n=1.

AFAIK, nonzero returns just the array in 1d case. Though I would recommend to 
use fancy indexing (i.e. t[t>0.5] ) whenever possible, it is way faster.

HTH,
Johannes


More information about the SciPy-user mailing list