From: Magnus L. H. <ma...@he...> - 2002-12-15 22:09:26
|
Magnus Lie Hetland <ma...@he...>: [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 |