[Numpy-discussion] *= operator not intuitive
Paul Anton Letnes
paul.anton.letnes at gmail.com
Wed Mar 16 10:58:48 EDT 2011
On 16. mars 2011, at 15.49, Chris Barker wrote:
> On 3/16/11 6:34 AM, Charles R Harris wrote:
>> On Wed, Mar 16, 2011 at 7:24 AM, Paul Anton Letnes
>
>> Yes, it is intentional. Numpy is more C than Python in this case,
>
> I don't know that C has anything to do with it -- the *= operators were
> added specifically to be "in-place" operators -- otherwise they would be
> nothing but syntactic sugar. And IIRC, numpy was one of the motivators.
>
> IMHO, the mistake was even allowing += and friends for immutables, as
> that inherently means something different.
>
> Of course, using += with integers is probably the most common case.
>
> -Chris
I see. In that case, I have the following either/or christmas wish:
Either: implement a warning along the following lines:
>>> from numpy import *
>>> a = zeros(10, dtype=complex)
>>> a.astype(float)
/Users/paulanto/Library/Python/2.7/bin/bpython:2: ComplexWarning: Casting complex values to real discards the imaginary part
# EASY-INSTALL-ENTRY-SCRIPT: 'bpython==0.9.7.1','console_scripts','bpython'
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
Or: give me a hint how and where to change the numpy code, and I could try to write a patch.
Paul.
More information about the NumPy-Discussion
mailing list