[Numpy-discussion] what goes wrong with cos(), sin()
Wed Feb 21 13:24:19 CST 2007
As far as a computer is concerned, those numbers are "around" zero -
"growing-up" w/ Matlab, e.g., one quickly learns to recognize these
numbers for what they are. One way to return zero for numbers like
if numpy.allclose(x, 0): return 0 (or 0*x to assure that 0 is the same
type as x),
but caveat emptor: sometimes, of course, 1e-16 really is supposed to be
1e-16, not just the best the algorithm can do to get to zero. Also,
(help me out here guys) I thought there was something like
zeroifclose(x) which does the above, or does numpy only have realifclose
to return a real when an imaginary part is close to zero?
> I'm quite new to numpy/scipy so please excuse if my problem is too obvious.
> example code:
> import numpy as n
> print n.sin(n.pi)
> print n.cos(n.pi/2.0)
> results in:
> I've expected something around 0. Can anybody explain what I am doing
> wrong here?
> Numpy-discussion mailing list
More information about the Numpy-discussion