np.pad

Pads the numpy array. By defaults it pads with constant value as shown below.

a = np.arange(5)
 
# array([0, 1, 2, 3, 4])
np.pad(a, (1, 1))
 
# array([0, 0, 1, 2, 3, 4, 0])

Looking at the tuple (1, 1) says 1 left and 1 right.

For 2d array,

a = np.arange(4).reshape(2, 2)
 
#array([[0, 1],
#       [2, 3]])
 
np.pad(a, ((1, 1), (1, 1)))
# array([[0, 0, 0, 0],
#      [0, 0, 1, 0],
#      [0, 2, 3, 0],
#      [0, 0, 0, 0]])

Again looking at the tuple for each dimension

  1. for dimension 0, it is one top and one bottom
  2. for dimension 1, it one left and one right.