-1

I have a bit of code that runs some stats for a moving 3D window at varying size. I have created a loop to to do this in increments of 5 from 5 to 50 as below.

For example first X = 5, Y = 5, Z = 5, then X = 10, Y = 10, z = 10 etc.

This works fine, but what I'd like to do is run the loop with every possible combination of X, Y and Z in increments of 5.

For example

X  Y  Z
5  5  5
10 5  5
15 5  5
.. .. ..
50 5  5
5  10 5
5  15 5
5  20 5
.. .. ..
10 10 5
10 15 5

etc,

so all in all it would be 1000 possible combinations I think

Can i do this with something like itertools.permutations?

I'm pretty new to python and coding so help would be much appreciated

#python code
sizeX = (0)
sizeY = (0)
sizeZ = (0)
count = (0)

for i in range(0,10):
 count = (count + 1)           
 sizeX = (sizeX + 5)
 sizeY = (sizeY + 5)
 sizeZ = (sizeZ + 5) 

#run the code
georich
  • 1
  • 2
  • It's not clear what you mean by *"every possible combination of X, Y and Z in increments of 5"*. Can you show your expected output/example? – Austin May 29 '19 at 17:59
  • `range(0,55,5)` will give you `0,5,10,..,50`. You can combine ranges like that with `itertools` functions. – Blorgbeard May 29 '19 at 18:00
  • You aren't looking for permutations (different ways of arranging things); you are looking for different ways to draw from 3 different sets (cartesian product). – Scott Hunter May 29 '19 at 18:00
  • Thanks all for astonishingly quick responses. Cartesian products does sound like what I'm looking for. I'll add an example of the expected outcome. – georich May 29 '19 at 18:11

1 Answers1

0

If you know you will have 3 variables for certain, you can use nested for loops with range:

for i in range(5, 55, 5):
    for j in range(5, 55, 5):
        for k in range(5, 55, 5):
            print(i, j, k)
N Chauhan
  • 3,407
  • 2
  • 7
  • 21