[Numpy-discussion] A couple more Numeric incompatibilities and a possible bug
Gary Ruben
gazzar at email.com
Fri Mar 26 23:17:01 CST 2004
I found a couple more incompatibilities between Numeric and numarray object array handling.
When I print an object array in Numeric, if the __str__ method exists for the contained object type, Numeric uses it to print the object.
However, numarray uses the __repr__ method instead.
This breaks my doctest strings
I think Numeric does it correctly.
In my example I have a class called Err with
def __repr__(self):
return "Err(%s,%s,%s)" % (self.value, self.posErr, self.negErr)
def __str__(self):
return "%s +%s/-%s" % (self.value, self.posErr, self.negErr)
Numeric behaves as follows (Note: ArrayOfErr() is just building an object array):
>>> print ArrayOfErr([909., 802., 677., 585.], 1.0)
[909.0 +1.0/-1.0 802.0 +1.0/-1.0 677.0 +1.0/-1.0 585.0 +1.0/-1.0 ]
whereas numarray does this:
>>> print ArrayOfErr([909., 802., 677., 585.], 1.0)
[Err(909.0,1.0,1.0), Err(802.0,1.0,1.0), Err(677.0,1.0,1.0),
Err(585.0,1.0,1.0)]
It also appears that if you try to apply the funtion abs to a built-in Python number type
after doing a 'from numarray import *',
instead of using Python's abs() function as Numeric does and returning a number, numarray
creates an ObjectArray containing the number and returns it. This may be a bug. Note also
the different answer when an int or float type is passed as an argument to cos:
>>> from Numeric import *
>>> cos(1)
0.54030230586813977
>>> cos(1.)
0.54030230586813977
>>> abs(-1)
1
>>> from numarray import *
>>> cos(1)
0.54030227661132813
>>> cos(1.)
0.54030230586813977
>>> abs(-1)
ObjectArray(1)
--
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm
More information about the Numpy-discussion
mailing list