|
From: Alan G I. <ai...@am...> - 2005-09-22 22:17:16
|
On Thu, 22 Sep 2005, Andrea Riciputi apparently wrote:=20 > I've already tried something like this, but it doesn't work since f1=20 > and f2 return not valid values outside the range over they are=20 > defined. Perhaps an example could clarify; suppose that f1(x) =3D 1./=20 > sqrt(1 - x**2) for x <=3D 1, and f2(x) =3D 1./sqrt(x**2 - 1) for x > 1.= =20 > Your suggestion, as the other I've tried, fails with a=20 > "OverflowError: math range error".=20 If you do it as I suggested, they should not I believe be=20 evaluated outside of their range. So your function must be=20 generating an overflow error within this range. >>> import math >>> import random >>> def f1(x): return math.sqrt(1-x**2) ... >>> def f2(x): return 1./math.sqrt(x**2-1) ... >>> def f(x): return x<=3D1 and f1(x) or f2(x) ... >>> d =3D [random.uniform(0,2) for i in range(20)] >>> fd =3D [f(x) for x in d] Works fine. Cheers, Alan Isaac |