[Numpy-discussion] cos -- NameError: global name 'cos' is not defined
Mon Dec 21 13:44:44 CST 2009
Yes, one can get both sin and cos via the interactive shell, if math is
imported as you have done.
However, I thought math itself always present to a program module? In
my program, sin exists but not cos, so one is forced to use math.cos().
Why one but not the other?
Keith Goodman wrote:
> On Mon, Dec 21, 2009 at 9:40 AM, Wayne Watson
> <email@example.com> wrote:
>> 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.
> NameError: name 'sin' is not defined
> Oh, right, there is no built-in sin function. I need to import it:
>>> import numpy as np
>>> import math
>>> from numpy import sin
> NumPy-Discussion mailing list
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet
"... humans'innate skills with numbers isn't much
better than that of rats and dolphins."
-- Stanislas Dehaene, neurosurgeon
Web Page: <www.speckledwithstars.net/>
More information about the NumPy-Discussion