-1
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)

I want to pad a matrix with border of 1 but this error shows up

any help is appriciated

mbauman
  • 30,958
  • 4
  • 88
  • 123
Who am I
  • 109
  • 6

1 Answers1

1

You must provide a correct input matrix! The length of the last row of s is 9, while all the other lengths are 8.

Here is your current "matrix". It's clearly wrong!

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]]
Riccardo Bucco
  • 13,980
  • 4
  • 22
  • 50