Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def pad_image(image: np.ndarray, pad_size: int) -> np.ndarray:
- if pad_size < 1:
- raise ValueError
- res = np.array([])
- m = image.shape[0]
- n = image.shape[1]
- if image.ndim == 2:
- res = np.zeros(shape = (m + 2 * pad_size, n + 2 * pad_size))
- elif image.ndim == 3:
- k = image.shape[2]
- res = np.zeros(shape=(m + 2 * pad_size, n + 2 * pad_size, k))
- res[pad_size: pad_size + m, pad_size: pad_size + n] = image
- return res
- """
- matrix = np.array([
- np.array([1,1,1,1,1,1,1]),
- np.array([1,1,1,1,1,1,1]),
- np.array([1,1,1,1,1,1,1])
- ])
- res = pad_image(matrix, 2)
- print("res")
- print(res)
- """
- MATRIX = np.full((2, 3, 7), 5)
- print(MATRIX)
- RES = pad_image(MATRIX, 2)
- print("RES")
- print(RES)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement