[SciPy-dev] In-place operators and casting

Alan G Isaac aisaac at american.edu
Thu Nov 24 09:02:52 EST 2005


On Thu, 24 Nov 2005, Ed Schofield apparently wrote: 
>>> c = zeros(10)
>>> c += rand(10)
>>> c
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
> Comments? 

User perspective:

Having that result differ from the result of
c=array([ci+ri for ci,ri in zip(c,rand(10))])
certainly feels weird.  I doubt anyone expects or wants the 
current behavior except those who have already been bitten,
figured it out, and then got used to it.

That said, there seems to be a conflict between a
"user friendly" approach and the possible fixes.
I think the "user friendly" approach would be a flag that 
sets the default return type of scipy functions (like zeros)  
to float.

Anyway, in this case I favor an exception.
Otherwise users will be constantly surprised.

Cheers,
Alan Isaac







More information about the SciPy-Dev mailing list