为什么我收到此错误?错误似乎在调用'for i in range'的行中,但我不明白为什么这会是一个错误...我已经退出内核以防万一隐藏在i中。
我的代码如下:
import os, sys
import numpy
from matplotlib import pylab, pyplot, cm
from math import pi
from skimage import io
image = numpy.ones([44,44],dtype = float)
imrange = len(image)
#Initialize empty residue map
residue_map = numpy.empty([imrange-2,imrange-2],dtype = float)
#Calculate the residues for each point following formula (1) in He paper
for i in range (1,int(imrange-1)):
for j in range (1,int(imrange-1)):
value = (image[i+1][j] - image[i][j]) + (image[i+1][j+1] -
image[i+1][j]) + (image[i][j+1] - image[i+1][j+1]) + (image[i][j] - image[i][j+1])
if value/2./pi > 0:
residue_map[i-1][j-1] = 1.
elif value/2./pi == 0:
residue_map[i-1][j-1] = 0.
else:
residue_map[i-1][j-1] = -1.
答案 0 :(得分:0)
另一个在python中成为初学者的情况....上面的代码工作,因为我定义了一个范围= numpy.max(图像) - numpy.min(图像),然后在循环中再次使用范围,因此错误!!