[Numpy-discussion] Re: Ransom Proposals
Travis Oliphant
oliphant at ee.byu.edu
Mon Mar 27 16:37:01 EST 2006
Robert Kern wrote:
>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]
>
>
>
True, true. So, why this behavior? This seems like a Python issue.
Compare
a = range(10)
b = arange(10,20)
a.__iadd__(b)
with
a += b
Shouldn't these be equivalent?
-Travis
More information about the NumPy-Discussion
mailing list