【发布时间】:2014-01-04 16:30:25
【问题描述】:
我正在尝试进行一些分形图像处理,但在运行我的代码时,我被告知
Traceback (most recent call last):
File "all_the_maps.py", line 72, in <module>
(xh, yh) = Hf(xf,yf,r)
TypeError: 'float' object is not iterable
相关代码块是
(xf,yf) = (0,0)
(xh,yh) = (0,0)
for n in xrange(N):
r = random.randint(1,10000)
(xf,yf) = F(xf,yf,r)
(xh,yh) = Hf(xh,yh,r)
h[int(round(xh)),int(round(yh))] = f[int(round(xf)),
int(round(yf))]
完整的文件在http://pastebin.com/kbJD3BK9(它很长,我不太擅长python,所以读起来可能会很痛苦)。
我看过其他人收到此错误,似乎他们正在迭代无法迭代的东西(例如 for i in 7: 而不是 for i in range(7): )。但是,这似乎不是我做错了什么,我真的不知道该怎么做。如果有人可以提供帮助,将不胜感激。
编辑:Hf 定义为:
def Hf(x,y,r):
if r <= 10000*a*b:
return 0.5*x, 0.5*y
elif r <= 10000*b:
return 0.5*x + 255.0
elif r <= 10000*(1 - a + a*b):
return 0.5*x + 255.0, 0.5*y + 255.0
else:
return 0.5*x, 0.5*y + 255.0
【问题讨论】:
-
你能把函数
Hf发在这里吗?
标签: python python-2.7 for-loop typeerror iterable