Question

I'm trying to do some fractal image processing, and when running my code, I get told

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

The relevant code block is

(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))]

and the full file is at http://pastebin.com/kbJD3BK9 (it's pretty long and I'm not very good at python, so it might be painful to read).

I've looked at other people getting this error, and it seems like they're iterating over something that can't be iterated over (e.g. for i in 7: instead of for i in range(7): ). However, this doesn't seem to be what I'm doing wrong, and I don't really have any idea what to do. If anyone could help, it would really be appreciated.

EDIT: Hf is defined as:

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
Était-ce utile?

La solution

Your second case

elif r <= 10000*b:
    return 0.5*x + 255.0

doesn't return a tuple like the others.

To clarify - in your main program, in the line (xh,yh) = Hf(xh,yh,r), you're expecting two items on the right hand side. If r <= 10000*b, Hf will only return a single float rather than the tuple that the other cases return.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top