np.pad

import numpy as np

if __name__ == '__main__':

    a = np.array([[1, 5, 5, 2],
                  [9, 6, 2, 8],
                  [3, 7, 9, 1]])
    b = np.pad(a, ((1, 2), (3, 4)))
    print(b)
[[0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 1 5 5 2 0 0 0 0]
 [0 0 0 9 6 2 8 0 0 0 0]
 [0 0 0 3 7 9 1 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 0 0]]
文章目录