``````

In [1]:

import numpy as np

``````
``````

In [2]:

a_1d = np.arange(4)
print(a_1d)

``````
``````

[0 1 2 3]

``````
``````

In [3]:

print(a_1d[[0, 2]])

``````
``````

[0 2]

``````
``````

In [4]:

print(a_1d[[0, 3, 2, 1, 2, -1, -2]])

``````
``````

[0 3 2 1 2 3 2]

``````
``````

In [5]:

print(a_1d[np.array([0, 3, 2, 1, 2, -1, -2])])

``````
``````

[0 3 2 1 2 3 2]

``````
``````

In [6]:

a_2d = np.arange(12).reshape(3, 4)
print(a_2d)

``````
``````

[[ 0  1  2  3]
[ 4  5  6  7]
[ 8  9 10 11]]

``````
``````

In [7]:

print(a_2d[[0, 2]])

``````
``````

[[ 0  1  2  3]
[ 8  9 10 11]]

``````
``````

In [8]:

print(a_2d[:, [0, 2]])

``````
``````

[[ 0  2]
[ 4  6]
[ 8 10]]

``````
``````

In [9]:

print(a_2d[[0, 2], [0, 2]])

``````
``````

[ 0 10]

``````
``````

In [10]:

print(a_2d[np.ix_([0, 2], [0, 2])])

``````
``````

[[ 0  2]
[ 8 10]]

``````
``````

In [11]:

print(a_2d[np.ix_([0, 2, 1, 1, -1, -1], [0, 2, 1, 3])])

``````
``````

[[ 0  2  1  3]
[ 8 10  9 11]
[ 4  6  5  7]
[ 4  6  5  7]
[ 8 10  9 11]
[ 8 10  9 11]]

``````
``````

In [12]:

print(a_2d[:, [1]])

``````
``````

[[1]
[5]
[9]]

``````
``````

In [13]:

print(a_2d[:, [1]].shape)

``````
``````

(3, 1)

``````
``````

In [14]:

print(a_2d[:, 1])

``````
``````

[1 5 9]

``````
``````

In [15]:

print(a_2d[:, 1].shape)

``````
``````

(3,)

``````