0

Hello, I'm trying to make a simple iteration to get 1000 vectors to used them in another calculation, I >have tried many things but still I'm getting this error of "float" object is not iterable when I'm >using while. Here is my script:

import random
count = 1000
alfa_1 = [0, 1]
alfa_2 = [0, 1]
d = [0, 1]
while count > 0:
    print count
    for i in range(count):
        alfa_1 = random.random () * (max (alfa_1) - min(alfa_1)) + min (alfa_1)
        alfa_2 = random.random () * (max(alfa_2) - min(alfa_2)) + min (alfa_2)
        d = random.random () * (max(d) - min(d)) + min(d)
        paramvect = [alfa_1, alfa_2, d]
        print paramvect
        count = count - 1

Thanks for any help you can provide!

1 Answer 1

5

You initially assign alfa_1 and alfa_2 list values, but later assign them to float values.

# As lists
alfa_1 = [0, 1]
alfa_2 = [0, 1]
...
# As floats
alfa_1 = random.random () * (max (alfa_1) - min(alfa_1)) + min (alfa_1)
alfa_2 = random.random () * (max(alfa_2) - min(alfa_2)) + min (alfa_2)

Consequently, on the second iteration of the loop, you pass max a float when it expects something iterable (like a list). (It's not clear what the goal is here so I can't offer a more complete solution.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.