Ad

Set All The Possible Variables In Range Python

- 1 answer

I one to try to create a big loop to try two variables in one time for each loop with -1<=a<=1 and -1<=b<=1 with an increment of 0.0001 in my function.

Question

I can get different results coming from the a and b variables.

Ad

Answer

Just use a nested loop

import numpy as np
for a in np.arange(-1, 1.0001, 0.0001):
    for b in np.arange(-1, 1.0001, 0.0001):
        print(a + b)

If you don't need/want numpy

for a in range(-1000, 1001):
    for b in range(-1000, 1001):
        print(a/1000 + b/1000)
Ad
source: stackoverflow.com
Ad