📜  添加填充到二维矩阵 \np - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:36.331000             🧑  作者: Mango

代码示例1
import numpy as np
# https://numpy.org/doc/stable/reference/generated/numpy.pad.html
image = np.ones((2,2), dtype=int)

padded_image = np.pad(image, 1, dtype=int, mode='constant')

print(padded_image)
# [[0 0 0 0]
#  [0 1 1 0]
#  [0 1 1 0]
#  [0 0 0 0]]