I'm trying to write a function to pass a variable into a piecewise function, I have:
def trans(a):
np.piecewise(a, [(a<.05) & (a>=0),
(a<.1) & (a>= .05),
(a<.2) & (a>=.1),
(a<.4) & (a>=.2),
(a<1) & (a>=.4)],
[0,1,2,3,4])
However, when I run trans(a)
, I get:
ValueError: function list and condition list must be the same
The function and condition list I used are both length 5, so I'm not sure what the issue is
EDIT: Apparently numpy.piecewise expects an array, so I needed to pass it one, instead of a plain variable?