[Numpy-discussion] Questions on np.piecewise
Joe
solarjoe at posteo.org
Fri Sep 15 11:25:11 EDT 2017
> Your example doesn't run, but here is one that does:
>
> In [8]: x = np.array([50], dtype=float)
>
> In [9]: np.piecewise(x, [0 < x <= 90, 90 < x <= 180], [1.1, 2.1])
> array([ 1.1])
>
> The answer to your second question is that it is returning an array
> with the same dtype as its first argument.
>
> The answer to your first question is "yes", and evidently if more than
> one condition matches, it is the last that prevails:
>
> In [10]: np.piecewise(x, [0 < x <= 90, 90 < x <= 180, 30<x<80], [1.1,
> 2.1, 3.3])
> array([ 3.3])
Thank you very much for the good answer!
More information about the NumPy-Discussion
mailing list