[Numpy-discussion] Casting Bug or a "Feature"?

Dag Sverre Seljebotn d.s.seljebotn@astro.uio...
Thu Jan 17 06:49:09 CST 2013


On 01/17/2013 01:27 PM, josef.pktd@gmail.com wrote:
> On Thu, Jan 17, 2013 at 2:34 AM, Matthieu Brucher
> <matthieu.brucher@gmail.com> wrote:
>> Hi,
>>
>> Actually, this behavior is already present in other languages, so I'm -1 on
>> additional verbosity.
>> Of course a += b is not the same as a = a + b. The first one modifies the
>> object a, the second one creates a new object and puts it inside a. The
>> behavior IS consistent.
>
> The inplace operation is standard, but my guess is that the silent
> downcasting is not.
>
> in python
>
>>>> a = 1
>>>> a += 5.3
>>>> a
> 6.2999999999999998
>>>> a = 1
>>>> a *= 1j
>>>> a
> 1j
>
> I have no idea about other languages.

I don't think the comparison with Python scalars is relevant since they 
are immutable:

In [9]: a = 1

In [10]: b = a

In [11]: a *= 1j

In [12]: b
Out[12]: 1


In-place operators exists for lists, but I don't know what the 
equivalent of a down-cast would be...

In [3]: a = [0, 1]

In [4]: b = a

In [5]: a *= 2

In [6]: b
Out[6]: [0, 1, 0, 1]

Dag Sverre



More information about the NumPy-Discussion mailing list