[SciPy-user] scipy casting behavior and scipy.sign error

p.berkes at biologie.hu-berlin.de p.berkes at biologie.hu-berlin.de
Thu Sep 23 07:18:26 CDT 2004


I noticed an inconsistent casting behavior of scipy when adding or
subtracting zero-dimensional arrays. For example, the result of a byte
plus a long is an integer, while a long plus a byte is a Python scalar
(i.e. not an array anymore). Does this have a explanation?

>>> import scipy
>>> scipy.scipy_base_version.scipy_base_version
'0.3.1_20.301'
>>> scipy.Numeric.__version__
'23.3'
>>> b = scipy.asarray(1,"b")
>>> l = scipy.asarray(1,"l")
>>> (b+l).typecode()
'i'
>>> (l+b).typecode()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'int' object has no attribute 'typecode'
>>> (b-l).typecode()
'i'
>>> (-l+b).typecode()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'int' object has no attribute 'typecode'

Moreover, this behavior changes after a call to alter_numeric, causing an
error in scipy.sign and possibly other functions (make sure you have the
latest CVS version of scipy_base, since otherwise the alter_numeric
function does not change the casting defaults of Numeric).

>>> scipy.sign(-1)
>>> -1
>>> scipy.alter_numeric()
>>> (-l+b).typecode()
'b'
>>> scipy.sign(-1)
>>> 255

Thank you for any comment,
Pietro.






More information about the SciPy-user mailing list