# SOLVED: numpy array indexing with lists and arrays

abc:

I have:

``>>> aarray([[1, 2],       [3, 4]])>>> type(l), l # list of scalers(, [0, 1])>>> type(i), i # a numpy array(, array([0, 1]))>>> type(j), j # list of numpy arrays(, [array([0, 1]), array([0, 1])])``

When I do

``>>> a[l] # Case 1, l is a list of scalers``

I get

``array([[1, 2],       [3, 4]])``

which means indexing happened only on 0th axis.

But when I do

``>>> a[j] # Case 2, j is a list of numpy arrays``

I get

``array([1, 4])``

which means indexing happened along axis 0 and axis 1.

Q1: When used for indexing, why is there a difference in treatment of list of scalers and list of Numpy arrays ? (Case 1 vs Case 2). In Case 2, I was hoping to see indexing happen only along axis 0 and get

``array( [[[1,2],          [3,4]],         [[1,2],         [3,4]]])``

Now, when using numpy array of arrays instead

``>>> j1 = np.array(j) # numpy array of arrays``

The result below indicates that indexing happened only along axis 0 (as expected)

``>>> a[j1] Case 3, j1 is a numpy array of numpy arraysarray([[[1, 2],        [3, 4]],       [[1, 2],        [3, 4]]])``

Q2: When used for indexing, why is there a difference in treatment of list of numpy arrays and numpy array of numpy arrays? (Case 2 vs Case 3)

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
HERE

This post first appeared on Stack Solved, please read the originial post: here

# Share the post

SOLVED: numpy array indexing with lists and arrays

×