[SciPy-User] unexpected behavior when reverting twice ([::-1, 0])

Robert Kern robert.kern at gmail.com
Mon May 9 16:40:55 EDT 2011


On Mon, May 9, 2011 at 15:06, Bastian Weber
<bastian.weber at gmx-topmail.de> wrote:
>
>>> I would have expected the first column of c to be [0,1,2,3,4] an b to be
>>> the same as in step 5.
>>
>> c[::-1,0] makes a view on c, not a copy. When you assign back into
>> c[:,0], you end up modifying the elements near the end of c[::-1,0]
>> (i.e. near the beginning of c[:,0]).
>>
>
> Ah, OK. As I expected: the bug was in front of the monitor. ;)
>
> I already guessed, that it might have to do with views at first... but
> then I tried it with np.flipud(...) and got the same results. Does this
> mean flipud creates a view too?

Yes.

> And is there a short syntax for creating a revered copy?

b = c[::-1].copy()

> Is there some document about the view-concept, its properties and
> possible pitfalls?

http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

-- 
Robert Kern

"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 SciPy-User mailing list