[SciPy-User] numpy.piecewise doesn't work with lists, only ndarrays

eat e.antero.tammi@gmail....
Mon Oct 8 16:45:44 CDT 2012


On Tue, Oct 9, 2012 at 12:35 AM, eat <e.antero.tammi@gmail.com> wrote:

> Hi,
>
> On Tue, Oct 9, 2012 at 12:14 AM, Juan Luis Cano Rodríguez <
> juanlu001@gmail.com> wrote:
>
>> I have noticed this behaviour of numpy.piecewise:
>>
>> In [1]: import numpy as np
>>
>> In [2]: q = [1, 2, 3, 4, 5, 6]
>>
>> In [3]: np.piecewise(q, [q < 3, 3 <= q], [-1, 1])
>> Out[3]: array([ 1, -1,  0,  0,  0,  0])
>>
> FWIF, when q is list this doesn't make sense:
> In []: [q< 3, 3<= 3]
> Out[]: [False, True]
> but with array it makes sense:
> In []: q= array(q)
> In []: [q< 3, 3<= 3]
> Out[]: [array([ True,  True, False, False, False, False], dtype=bool),
> True]
>
Heh, obviously my intention was (:
In []: [q< 3, 3<= q]
Out[]:
[array([ True,  True, False, False, False, False], dtype=bool),
 array([False, False,  True,  True,  True,  True], dtype=bool)]


>
> IMO, np.piecewise() should just work with arrays as documented.
>
>
> My 2 cents,
> -eat
>
>
>>
>> In [4]: q = np.array(q)
>>
>> In [5]: np.piecewise(q, [q < 3, 3 <= q], [-1, 1])
>> Out[5]: array([-1, -1,  1,  1,  1,  1])
>>
>> Maybe the function should work the same both with lists and arrays?
>> Should I file a bug?
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20121009/b27045c2/attachment.html 


More information about the SciPy-User mailing list