[Numpy-discussion] Re: Ransom Proposals
Robert Kern
robert.kern at gmail.com
Mon Mar 27 15:52:06 EST 2006
Travis Oliphant wrote:
> Tim Hochberg wrote:
>
>>> Charles R Harris wrote:
>>>
>>> >>> l = list(a)
>>> >>> l
>>> [999, 1, 2, 3, 4, 5, 6, 7, 8]
>>> >>> a
>>> array([999, 1, 2, 3, 4, 5, 6, 7, 8])
>>> >>> l += a
>>> >>> l
>>> array([1998, 2, 4, 6, 8, 10, 12, 14, 16])
>>> >>> a
>>> array([999, 1, 2, 3, 4, 5, 6, 7, 8])
>>
>> Let me add that I think that this is pretty dubious, so if this is a
>> new feature, perhaps we should revert it before it becomes entrenched.
>
> I don't think it's a new feature, but it's simply the result of
>
> l += a being translated to
>
> l = l + a # lists don't have in-place add's
>
> Numeric has this behavior as well.
Lists do have in-place adds.
In [1]: a = range(10)
In [2]: b = range(10, 20)
In [3]: id(a)
Out[3]: 92350264
In [4]: a += b
In [5]: id(a)
Out[5]: 92350264
In [6]: a
Out[6]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
--
Robert Kern
robert.kern at gmail.com
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion
mailing list