mirror of
https://github.com/davrot/pytutorial.git
synced 2025-04-16 12:16:42 +02:00
|
||
---|---|---|
.. | ||
README.md |
Piecewise
{:.no_toc}
* TOC {:toc}Top
Questions to David Rotermund
numpy.piecewise
numpy.piecewise(x, condlist, funclist, *args, **kw)
Evaluate a piecewise-defined function.
Given a set of conditions and corresponding functions, evaluate each function on the input data wherever its condition is true.
import numpy as np
a = np.arange(1, 11)
b = np.piecewise(a, [a < 5, a == 0, a > 5], [-1, 0, 1])
print(a) # -> [ 1 2 3 4 5 6 7 8 9 10]
print(b) # -> [-1 -1 -1 -1 0 1 1 1 1 1]