``````

In [1]:

import numpy as np

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

In [2]:

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

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

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

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

In [3]:

print(a_1d[2:7])

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

[2 3 4 5 6]

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

In [4]:

print(a_1d[:7])

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

[0 1 2 3 4 5 6]

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

In [5]:

print(a_1d[2:])

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

[2 3 4 5 6 7 8 9]

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

In [6]:

print(a_1d[2:7:2])

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

[2 4 6]

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

In [7]:

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

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

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

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

In [8]:

print(a_2d[:2, 1:3])

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

[[1 2]
[5 6]]

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

In [9]:

print(a_2d[:2, :])

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

[[0 1 2 3]
[4 5 6 7]]

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

In [10]:

print(a_2d[:2])

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

[[0 1 2 3]
[4 5 6 7]]

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

In [11]:

print(a_2d[1:2])

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

[[4 5 6 7]]

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

In [12]:

print(a_2d[1:2].shape)

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

(1, 4)

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

In [13]:

print(a_2d[1])

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

[4 5 6 7]

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

In [14]:

print(a_2d[1].shape)

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

(4,)

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

In [15]:

print(a_2d[:, 2:3])

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

[[ 2]
[ 6]
[10]]

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

In [16]:

print(a_2d[:, 2:3].shape)

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

(3, 1)

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

In [17]:

print(a_2d[:, 2])

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

[ 2  6 10]

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

In [18]:

print(a_2d[:, 2].shape)

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

(3,)

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

In [19]:

print(a_2d[1:2, 2:3])

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

[[6]]

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

In [20]:

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

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

(1, 1)

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

In [21]:

print(a_2d[1, 2])

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

6

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

In [22]:

print(type(a_2d[1, 2]))

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

<class 'numpy.int64'>

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

In [23]:

a_3d = np.arange(24).reshape(2, 3, 4)
print(a_3d)

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

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

[[12 13 14 15]
[16 17 18 19]
[20 21 22 23]]]

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

In [24]:

print(a_3d[0, 0, 0])

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

0

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

In [25]:

print(a_3d[0, 0])

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

[0 1 2 3]

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

In [26]:

print(a_3d[0])

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

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

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

In [27]:

print(a_3d[0:1, 0:1, 0:1])

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

[[[0]]]

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

In [28]:

print(a_3d[0:1, 0:1])

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

[[[0 1 2 3]]]

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

In [29]:

print(a_3d[0:1])

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

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

``````