[Numpy-discussion] Piecewise functions.

Andrea Riciputi ariciputi at pito.com
Fri Sep 23 00:03:07 EDT 2005


On Sep 23, 2005, at 5:23 AM, Greg Ewing wrote:

> I wish people would stop suggesting the 'a and b or c' trick,
> because it DOESN'T WORK except in special circumstances (i.e.
> when you can be sure that b is never false).
>
> What you want is:
>
>   def f(x):
>     if x <= a:
>       return f1(x)
>     else:
>       return f2(x)

It doesn't work either. As I've already explained x is an array  
containing values both above and below a!

What I really need is a way to prevent f1 and f2 from acting on those  
values of the 'x' array for which the functions are not defined.

Any other hints?
  Andrea.





More information about the NumPy-Discussion mailing list