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

Bastian Weber bastian.weber at gmx-topmail.de
Mon May 9 15:13:07 EDT 2011


Hello,

I found an unexpected behavior when reverting an array and then 
reverting a part of it again (numpy version 1.3.0):


In [1]: import numpy as np

In [2]: a = np.arange(5)

In [3]: a
Out[3]: array([0, 1, 2, 3, 4])

In [4]: b = np.c_[a, a*3]

In [5]: b
Out[5]:
array([[ 0,  0],
        [ 1,  3],
        [ 2,  6],
        [ 3,  9],
        [ 4, 12]])

In [6]: c = b[::-1, :]

In [7]: c
Out[7]:
array([[ 4, 12],
        [ 3,  9],
        [ 2,  6],
        [ 1,  3],
        [ 0,  0]])

In [8]: c[:,0] = c[::-1, 0]

In [9]: c
Out[9]:
array([[ 0, 12],
        [ 1,  9],
        [ 2,  6],
        [ 1,  3],
        [ 0,  0]])

In [10]: b
Out[10]:
array([[ 0,  0],
        [ 1,  3],
        [ 2,  6],
        [ 1,  9],
        [ 0, 12]])





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.

This is how it continues with side effects which seem magical to me:

In [11]: c[:,0] = np.arange(5)

In [12]: c
Out[12]:
array([[ 0, 12],
        [ 1,  9],
        [ 2,  6],
        [ 3,  3],
        [ 4,  0]])

In [13]: b
Out[13]:
array([[ 4,  0],
        [ 3,  3],
        [ 2,  6],
        [ 1,  9],
        [ 0, 12]])



In [14]: np.version.version
Out[14]: '1.3.0'


Do I misinterpret something or is this an version issue? Maybe its just 
on my machine..



Best regards,

Bastian.



More information about the SciPy-User mailing list