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

eat e.antero.tammi at gmail.com
Mon Oct 8 17:35:39 EDT 2012


Hi,

On Tue, Oct 9, 2012 at 12:14 AM, Juan Luis Cano Rodríguez <
juanlu001 at 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]

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 at 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/f99745d9/attachment.html>


More information about the SciPy-User mailing list