[Numpy-discussion] Unexpected change of array used to index another array

Webb Sprague webb.sprague at gmail.com
Sat Apr 8 20:02:11 CDT 2006


Hi.

I indexed an 10 x 10(called bigM below) with another array (OFFS_TMP
below).  I suppose because OFFS_TMP has negative numbers, it was
changed to cycle around to 9 wherever there is a negative 1 (which is
the forward version of -1 if you are a 10 x 10 matrix).  You can
analogous behavior with -2 => 8, etc.  Is changing the indexing matrix
really the correct behavior?  The result of using the index seems to
be fine.  Has this story been told already and I didn't know it?

Below is my ipython session.

In [57]: OFFS_TMP
Out[57]:
array([[-1,  1],
       [ 0,  1],
       [ 1,  1],
       [-1,  0],
       [ 0,  0],
       [ 1,  0],
       [-1, -1],
       [ 0, -1],
       [ 1, -1]])

In [58]: bigM[OFFS_TMP]
Out[58]:
array([[[False, True, False, False, True, False, True, True, True, False],
        [False, True, False, True, True, False, False, False, True, True]],

       [[True, False, True, False, True, True, False, False, False, True],
        [False, True, False, True, True, False, False, False, True, True]],

       [[False, True, False, True, True, False, False, False, True, True],
        [False, True, False, True, True, False, False, False, True, True]],

       [[False, True, False, False, True, False, True, True, True, False],
        [True, False, True, False, True, True, False, False, False, True]],

       [[True, False, True, False, True, True, False, False, False, True],
        [True, False, True, False, True, True, False, False, False, True]],

       [[False, True, False, True, True, False, False, False, True, True],
        [True, False, True, False, True, True, False, False, False, True]],

       [[False, True, False, False, True, False, True, True, True, False],
        [False, True, False, False, True, False, True, True, True, False]],

       [[True, False, True, False, True, True, False, False, False, True],
        [False, True, False, False, True, False, True, True, True, False]],

       [[False, True, False, True, True, False, False, False, True, True],
        [False, True, False, False, True, False, True, True, True,
False]]], dtype=bool)

In [59]: OFFS_TMP
Out[59]:
array([[9, 1],
       [0, 1],
       [1, 1],
       [9, 0],
       [0, 0],
       [1, 0],
       [9, 9],
       [0, 9],
       [1, 9]])




More information about the Numpy-discussion mailing list