[Numpy-discussion] cos -- NameError: global name 'cos' is not defined
Robert Kern
robert.kern@gmail....
Mon Dec 21 11:44:12 CST 2009
On Mon, Dec 21, 2009 at 11:40, Wayne Watson
<sierra_mtnview@sbcglobal.net> wrote:
> In this code,
> ===========start
> 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):
> acos(radians(D))
> return=====end
> 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().
--
Robert Kern
"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
mailing list