np.pad的解释

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]]

posted @ 2022-12-24 13:24  祥瑞哈哈哈  阅读(256)  评论(0)    收藏  举报