[Numpy-discussion] what goes wrong with cos(), sin()

Christopher Barker Chris.Barker@noaa....
Thu Feb 22 12:46:01 CST 2007


David L Goldsmith wrote:
> I agree w/ Chuck - I'd consider what Tim describes is happening a "bug".

It's not a bug, but it is a missing feature. numpy doesn't appear to 
convert strings to numbers for any of its own types:

 >>> N.float128("4.3")
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: a float is required
 >>> N.uint8("4")
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ValueError: setting an array element with a sequence.
 >>> N.uint16("4")
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ValueError: setting an array element with a sequence.
 >>> N.int16("4")
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ValueError: setting an array element with a sequence.

It works for "float" and "int":
 >>> N.float("4")
4.0
 >>> N.int("4")
4

Because these are built-in python types, and those constructors support 
initialization with strings.

Given that there are some numpy types that hold values that can not be 
initialized by standard python literals, it would be nice to be able to 
do this.

Oh, and here's another inconsistency:

 >>> N.int32("676")
676
 >>> N.uint32("676")
array([6, 7, 6], dtype=uint32)

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the Numpy-discussion mailing list