Introduction to NumPy

In [1]:
import numpy as np
In [2]:
cube = np.array([[[1,2], [3, 4]], [[5, 6], [7, 8]]])
print(cube)
[[[1 2]
  [3 4]]

 [[5 6]
  [7 8]]]
In [3]:
cube.ndim
Out[3]:
3
In [4]:
cube.shape
Out[4]:
(2, 2, 2)
In [5]:
cube[1, 1, 1]
Out[5]:
8
In [6]:
cube[0, 0]
Out[6]:
array([1, 2])

Or, equivalently (as a trailing : is always implied):

In [7]:
cube[0, 0, :]
Out[7]:
array([1, 2])
In [8]:
cube[:, 0, 1]
Out[8]:
array([2, 6])
In [9]:
cube[:, 1, :]
Out[9]:
array([[3, 4],
       [7, 8]])