[Numpy-discussion] *= operator not intuitive

Christopher Barker Chris.Barker at noaa.gov
Wed Mar 16 18:43:27 EDT 2011

On 3/16/11 9:22 AM, Paul Anton Letnes wrote:

>> This comes up for discussion on a fairly regular basis. I tend towards the more warnings side myself, but you aren't going to get the current behavior changed unless you can convince a large bunch of people that it is the right thing to do, which won't be easy.

Indeed, I don't think I'd want a warning for this -- though honestly, 
I'm not sure what you think should invoke a warning:

a = np.ones((3,), dtype=np.float32)

a + = 2.0

Should that be a warning? you are adding a 64 bit float to a 32bit float 

a = np.ones((3,), dtype=np.float32)

a + = 2

now you are adding an integer -- should that be a warning?

a = np.ones((3,), dtype=np.int32)

a + = 2.1

now a float to an integer array -- should that be a warning?

As you can see -- there are a lot of options. As there are defined as 
in-place operators, I don't expect any casting to occur.

I think this is the kind of thing that would be great to have a warning 
the first time you do it, but once you understand, the warnings would be 
really, really annoying!


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the NumPy-Discussion mailing list