向 python 中的列表添加边框 1
Adding a border of 1 to a list in python
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。
这是您当前的"matrix"。明显错了!
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]]
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。
这是您当前的"matrix"。明显错了!
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]]