[Numpy-discussion] cos -- NameError: global name 'cos' is not defined
Mon Dec 21 11:44:12 CST 2009
On Mon, Dec 21, 2009 at 11:40, Wayne Watson
> In this code,
> import math
> import numpy as np
> from numpy import matrix
> def sinD(D): # given in degrees, convert to radians
> return sin(radians(D))
> def cosD(D):
> return cos(radians(D)) <<--------------
> def acosD(D):
> the << line produces, "NameError: global name 'cos' is not defined", but
> the sin() above it does not? They are both built-in functions.
No, they aren't. They are in the math module. You want math.cos(). The
same goes for radians() and acos() and sin().
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion