[SciPy-User] numpy.piecewise doesn't work with lists, only ndarrays
Sebastian Berg
sebastian@sipsolutions....
Mon Oct 8 16:25:59 CDT 2012
Hey,
On Mon, 2012-10-08 at 23:14 +0200, Juan Luis Cano Rodríguez 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])
Note that [q < 3, 3 <= q] evaluates as [False, True] due to how
comparison with lists works in python. So you cannot expect a useful
result.
Regards,
Sebastian
> Out[3]: array([ 1, -1, 0, 0, 0, 0])
>
> 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
More information about the SciPy-User
mailing list