[Cython] Cython array type: Summary, introducing CEP 518
Stefan Behnel
stefan_ml at behnel.de
Thu Jun 18 19:31:02 CEST 2009
Dag Sverre Seljebotn wrote:
>> # Some ways of multiplying all elements with 2
>> x *= 2
>> x[...] *= 2
>> x[:,:] *= 2
>> x += x
>> x[...] += x
>
> OK I'll make an exception here -- I'm willing to discuss whether we
> should depart from NumPy semantics here and let
>
> x2 = x
> x *= 2
>
> allocate new memory, so that x2 is not modified, being consistent with a
> direct transformation to "x = x * 2". One can always write
>
> x[...] *= 2
>
> if one wishes to modify original memory.
What's wrong with
x = 2 * x2
for doing a copy ?
x *= 2
pretty clearly states that I want to modify x in place.
Stefan
More information about the Cython-dev
mailing list