[Numpy-discussion] Change in Python/Numpy numerics with Py version 2.6 ?
Fri Nov 12 09:58:39 CST 2010
----- Original Message ----
From: Robert Kern <firstname.lastname@example.org>
To: Discussion of Numerical Python <email@example.com>
Sent: Fri, November 12, 2010 10:39:54 AM
Subject: Re: [Numpy-discussion] Change in Python/Numpy numerics with Py version
On Fri, Nov 12, 2010 at 09:02, Lou Pecora <firstname.lastname@example.org> wrote:
> I ran across what seems to be a change in how numerics are handled in Python
> or Numpy 1.3.0 or both, I'm not sure. I've recently switched from using
> 2.4 and Numpy 1.0.3 to using the Python 2.6 and Numpy 1.3.0 that comes with
> which is a large mathematical package. But the issue seems to be a Python
> not a SAGE one.
> Here is a short example of code that gives the new behavior:
> # ---- Return the angle between two vectors ------------
> def get_angle(v1,v2):
> '''v1 and v2 are 1 dimensional numpy arrays'''
> # Make unit vectors out of v1 and v2
> return ang
> When using Python 2.6 with Numpy 1.3.0 and v1 and v2 are parallel the dot
> product of v1unit and v2unit sometimes gives 1.0+epsilon where epsilon is the
> smallest step in the floating point numbers around 1.0 as given in the sys
> module. This causes acos to throw a Domain Exception. This does not happen
> I use Python 2.4 with Numpy 1.0.3.
acos() is not a numpy function. It comes from the stdlib math module.
Python 2.6 tightened up many of the border cases for the math
functions. That is probably where the behavior difference comes from.
Thanks, Robert. I thought some math functions were replaced by numpy functions
that can also operate on arrays when using from numpy import *. That's the
reason I asked about numpy. I know I should change this.
But your explanation sounds like it is indeed in Py 2.6 where they tightened
things up. I'll just leave the check for exceptions in place and use it more
-- Lou Pecora, my views are my own.
NumPy-Discussion mailing list
More information about the NumPy-Discussion