0
我有打印出3x3矩陣的2×2矩陣卷積功能:類型錯誤在Python函數(int對象未標化)
image = [[1,0,1], # Original image
[0,1,0],
[1,0,1]]
在哪裏我的功能應該打印出來:
[1,0]
[0,1]
[0,1]
[1,0]
[0,1]
[1,0]
[1,0]
[0,1]
的功能如下
def convolution(image,result):
# Image being 2d matrix
# Result being return stacked 2d matrices
# DECLARE LOCAL VARIABLES
a = 0 # Slice [a:b]
b = 2
r = 0
# For row in image:
for row in image:
# While b < row length:
while b < len(row):
print(row[r][a:b]) # HERE IS THE ERROR
print(row[r+1][a:b])
a += 1
b += 1
a = 0 # Slice [a:b]
b = 2
matrix2d.clear()
我得到以下錯誤:
Traceback (most recent call last):
File "conv.py", line 49, in <module>
convolution(image,result3d)
File "conv.py", line 24, in convolution
print(row[r][a:b])
TypeError: 'int' object is not subscriptable
這個錯誤信息對我來說比較模糊。可以做些什麼來糾正這個錯誤?