np.pad就是把x的上下左右都补上维。 import numpy as np x=np.arange(12).reshape((3,4)) x=np.pad(x, [(2, 2), (2, 2)], mode='constant') print(x)
[[ 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0]
[ 0 0 0 1 2 3 0 0]
[ 0 0 4 5 6 7 0 0]
[ 0 0 8 9 10 11 0 0]
[ 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0]]