[Numpy-discussion] Index array confusion...
Magnus Lie Hetland
magnus at hetland.org
Sun Dec 15 14:10:01 EST 2002
Magnus Lie Hetland <magnus at hetland.org>:
[snip]
> This seems like a bug to me. The assignment ought to swap the tails of
> the sequences, as is the case with lists, but with numeric arrays,
> some weird form of overwriting occurs. I guess this may be an
> optimization (i.e. to avoid making copies), but it is rather
> confusing. What do you think?
Even stranger:
>>> a = zeros([5])
>>> b = ones([5])
>>> p = 2
>>> tail_a = a[p:]
>>> tail_b = b[p:]
>>> a[p:] = tail_b
>>> b[p:] = tail_a
>>> a, b
(array([0, 0, 1, 1, 1]), array([1, 1, 1, 1, 1]))
I suppose this is due to sharing of slices somehow? I.e:
>>> a = ones([5])
>>> b = a[:]
>>> b[2] = 0
>>> a
array([1, 1, 0, 1, 1])
I have to use the copy method here, I guess?
> > Todd
--
Magnus Lie Hetland Practical Python The Anygui Project
http://hetland.org http://ppython.com http://anygui.org
More information about the NumPy-Discussion
mailing list