[Numpy-discussion] Arcos returns nan

João Quinta da Fonseca joao.q.fonseca at gmail.com
Fri Mar 28 05:20:23 EDT 2008


I have a function that returns the dot product of two unit vectors.  
When I try to use arcos on the values returned I sometimes get the  
warning:
"Warning: invalid value encountered in arccos", and the angle  
returned is nan. I found out that this happens for essentially co- 
linear vectors, for which the dot product function returns 1.0.  This  
looks like 1.0 no matter how I print it but if I do: >>N.dot(a,b)>1,  
I get: >>True.
Now I guess this arises because of the way computers store floats but  
shouldn't numpy take care of this somehow? Is it a bug? I don't seem  
to have this problem with Matlab or Fortran.

João


More information about the NumPy-Discussion mailing list