[PYTHON MATRIX-SIG] Type coercion issues again - possible incompatibility in next release :-(

Timothy A. Hochberg hochberg@wwa.com
Sun, 9 Mar 1997 14:09:40 -0600 (CST)



On Sun, 9 Mar 1997, Konrad Hinsen wrote:

> > In fixing this bug, I noticed a laxness in a number of array functions for 
> > coercion with loss of precision.  For example, the following code runs 
> > without a hitch in NumPy-beta1
> > 
> > >>> from Numeric import *
> > >>> a = arange(10, typecode=Float)
> > >>> a
> > array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.])
> > >>> asarray(a, Int)
> > array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
> > 
> > While this is clearly not a problem in this case, in general it's a very 
> > dangerous thing to automatically coerce an array of floats to ints.
> 
> What's automatic in this case? There's an explicit 'Int' there, so
> I don't see a problem.
> 
> I agree, of course, that truly automatic conversion with loss of
> precision should not happen, even if that leads to somewhat incompatible
> behaviour.

I've been bitten a few times by the followiung behaviour.

a = NP.zeros((5,5))
a[3] = 1.5 # .5 is silently dropped
b = NP.zeros((5,5), NP..Float)
b[3] = 5 + 4j  # 4j silently dropped

Would the changes your proposing 'fix' this? Or am I gonna just have to
learn to be a little more careful in my coding....;)

-tim




_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________