I am trying to construct a piecewise function for some digital signal processing, but I cannot get numpy.piecewise to allow me to specify a range.
Here is what I want to input:
t = np.arange(-10,10,1)
x = lambda x: x**3
fx = np.piecewise(t, [t < -1 and t>-2, t <= 0 and t>-1, t>=0 and t<1,t>1 and t<2], [x(t + 2), x(-t),x(t),-x(2-t)])
plot(t,fx)
However, I get the error: "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
After dissecting the function, it seems the issue is that this function won't allow 2 conditions in one such as:
t < -1 and t>-2
But it seems to me that allowing a range to be specified would be essential to many piecewise functions. Is there a way to accomplish this?
Thanks!