# Import the NumPy library
import numpy as np
Z = np.random.randint(0, 5, (10, 10))
print(Z) # observe the (10x10) matrix
print()
n = 3
C = np.zeros((Z.shape[0]-n+1, Z.shape[1]-n+1, n, n), dtype=Z.dtype)
for i in range(C.shape[0]):
for j in range(C.shape[1]):
C[i, j] = Z[i:i+n, j:j+n]
print(C) # observe the (3x3) extracted matrix from the above (10x10) matrix