Problem p03574 (python)

Fixed submission:
H, W = map(int, input().split())
S =[input() for i in range(H)]

L = [""]*H
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
        L[i] += "#"
    else:
      c = sum(t[max(0,j-1):min(W,j+2)].count("#") for t in S[max(0,i-1):min(H,i+2)])
      L[i] += str(c)
for i in range(H):
  print(L[i])

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
import numpy as np
x = np.empty((H,W), dtype=object)
for i in range(H):
  x[i,] = map(int, input().split())

temp_list = []
for i in range(H):
  for j in range(W):
    if x[i,j] == "#":
      pass
    elif i == 0 and j == 0:
      temp_list = [x[i,j+1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0 and j == W-1:
      temp_list = [x[i,j-1],x[i+1,j],x[i+1,j-1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1 and j == 0:
      temp_list = [x[i-1,j],x[i-1,j+1],x[i,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1 and j == W-1:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i,j-1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0:
      temp_list = [x[i,j-1],x[i,j+1],x[i+1,j-1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1:
      temp_list = [x[i,j-1],x[i,j+1],x[i-1,j-1],x[i-1,j],x[i-1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == 0:
      temp_list = [x[i-1,j],x[i-1,j+1],x[i,j+1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == W-1:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i,j-1],x[i+1,j-1],x[i+1,j]]
      counts = temp_list.count("#")
      x[i,j] = counts
    else:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i-1,j+1],x[i,j-1],x[i,j+1],x[i+1,j-1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts

printlist = [""] * H
for i in range(H):
  for j in range(W):
    printlist[i] += str(x[i,j]) 

for i in range(H):
    print(printlist[i])

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
import numpy as np
x = np.empty((H,W), dtype=object)
for i in range(H):
  x[i,] = map(int, input().split())

temp_list = []
for i in range(H):
  for j in range(W):
    if x[i,j] == "#":
      continue
    elif i == 0 and j == 0:
      temp_list = [x[i,j+1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0 and j == W-1:
      temp_list = [x[i,j-1],x[i+1,j],x[i+1,j-1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1 and j == 0:
      temp_list = [x[i-1,j],x[i-1,j+1],x[i,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1 and j == W-1:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i,j-1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0:
      temp_list = [x[i,j-1],x[i,j+1],x[i+1,j-1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H-1:
      temp_list = [x[i,j-1],x[i,j+1],x[i-1,j-1],x[i-1,j],x[i-1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == 0:
      temp_list = [x[i-1,j],x[i-1,j+1],x[i,j+1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == W-1:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i,j-1],x[i+1,j-1],x[i+1,j]]
      counts = temp_list.count("#")
      x[i,j] = counts
    else:
      temp_list = [x[i-1,j-1],x[i-1,j],x[i-1,j+1],x[i,j-1],x[i,j+1],x[i+1,j-1],x[i+1,j],x[i+1,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts

printlist = [""] * H
for i in range(H):
  for j in range(W):
    printlist[i] += str(x[i,j]) 

for i in range(H):
    print(printlist[i])

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
import numpy as np
x = np.zeros((H,W))
for i in range(H):
  x[i,] = map(int, input().split())

temp_list = []
for i in range(H):
  for j in range(W):
    if x[i,j] == "#":
      continue
    elif i == 0 and j == 0:
      temp_list = [x[i,j+1],x[i+1,j:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0 and j == W:
      temp_list = [x[i,j-1],x[i+1,j:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H and j == 0:
      temp_list = [x[i-1,j:j+1],x[i,j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H and j == W:
      temp_list = [x[i-1,j-1:j],x[i,j-1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == 0:
      temp_list = [x[i,j-1],x[i,j+1],x[i+1,j-1:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif i == H:
      temp_list = [x[i,j-1],x[i,j+1],x[i-1,j-1:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == 0:
      temp_list = [x[i-1,j:j+1],x[i,j+1],x[i+1,j:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
    elif j == W:
      temp_list = [x[i-1,j-1:j],x[i,j-1],x[i+1,j-1:j]]
      counts = temp_list.count("#")
      x[i,j] = counts
    else:
      temp_list = [x[i-1,j-1:J+1],x[i,j-1],x[i,j+1],x[i+1,j-1:j+1]]
      counts = temp_list.count("#")
      x[i,j] = counts
      
for i in range(H):
  print(x[i,])