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

Travis E. Oliphant oliphant at ee.byu.edu
Thu Sep 23 17:52:48 CDT 2004


p.berkes at biologie.hu-berlin.de wrote:
> 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'

Thank you for your report.  Numeric has had some of these casting issues 
for a long time.    We can fix them with scipy.alter_numeric when we 
catch them if we think it is important.

BTW, there are still some casting issues in alter_numeric that have not 
been ironed out.   Thank you for your feedback.

-Travis O.





> 
>>>>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.
> 
> 
> 
> 
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list