# [SOLVED] Numpy Advanced Indexing confusion

## Issue

If a is numpy array of shape (5,3), b is of shape (2,2) and c is of shape (2,2), what is the shape of a[b,c]?

Can anyone explain this to me with an example. I’ve read the docs but still I am not able to understand how it works.

## Solution

Just for the purpose of expounding the concept of advanced indexing, here is a contrived example:

``````# input arrays
In : a
Out:
array([[ 0,  1,  2],
[ 3,  4,  5],
[ 6,  7,  8],
[ 9, 10, 11],
[12, 13, 14]])

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

In : c
Out:
array([[0, 1],
[2, 2]])

In : a[b, c]
Out:
array([[ 0,  4],
[ 8, 11]])
``````

By the expression `a[b, c]`, we are using the arrays `b` and `c` to selectively pull out elements from the array `a`.

To interpret the output of `a[b, c]`:

``````    # b            # c            # 2D indices
[[0, 1],       [[0, 1]   ---> (0,0)  (1,1)
[2, 3]]        [2, 2]]  ---> (2,2)  (3,2)
``````

The 2D indices would simply be applied to the array `a` and the corresponding elements would be returned as array in the result of `a[b, c]`

`````` a[(0,0)]  --> 0
a[(1,1)]  --> 4
a[(2,2)]  --> 8
a[(3,2)]  --> 11
``````

The above elements are returned as a 2D array since the arrays `b` and `c` are 2D arrays themselves.

``````In : (a[b, c]).flags.owndata