Example 1: declare numpy zeros matrix python
import numpy as np
dimensions = (3, 3)
np.zeros(dimensions)
Example 2: 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 3: numpy init array
a=[]
for i in range(8):
a.append(i)