import numpy as np
s=[[0, 0, 0, 0,0,0,0,0], [1, 1, 1, 1, 1,1,1, 0],[1, 1, 1, 1, 1,1,1, 0],[1,0,0,0,0,1,1,0],
[0,1,1,1,0,0,0,0],[0,1,1,1,1,1,1,1],[0,1,1,1,1,1,1,1],[0, 0, 0, 0, 0, 0,0,0,0]]
k=np.pad(s,((1,1),(1,1)),mode='constant',constant_values=1)
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (2,2) and requested shape (1,2)
我想填充边框为1的矩阵,但出现此错误
需要任何帮助
您必须提供正确的输入矩阵! s
的最后一行的长度为9,而其他所有长度均为8。
这里是您当前的“矩阵”。显然是错误的!
s = [[0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 0],
[1, 0, 0, 0, 0, 1, 1, 0],
[0, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0]]