Example 1: python how to pad a numpy array with zeros
np.pad(numpy_array, (pad_left, pad_right), 'constant')
np.pad(numpy_array, ((pad_top, pad_bottom), (pad_left, pad_right)), 'constant')
import numpy as np
numpy_array = np.array([1,2,3,4,5])
np.pad(numpy_array, (2, 3), 'constant')
--> array([0, 0, 1, 2, 3, 4, 5, 0, 0, 0])
numpy_array = np.array([[1,2],[3,4]])
array([[1, 2],
[3, 4]])
np.pad(numpy_array, ((1,2),(2,1)), 'constant')
array([[0, 0, 0, 0, 0],
[0, 0, 1, 2, 0],
[0, 0, 3, 4, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]])
Example 2: append a zeros column numpy
np.concatenate((np.zeros((3,3), dtype=int), arr), axis=1)
array([[0, 0, 0, 1, 2, 3],
[0, 0, 0, 4, 5, 6],
[0, 0, 0, 7, 8, 9]])