Tuple of coordinates

V

victor.herasme

Hi,

i am using a software which uses python as its scripting language. I
want to generate a list of coordinates more or less this way:

for i in (beg, end, step):
for j in (beg, end, step):
for k in (beg, end, step):
..........

Coords = ((i1,j1,k1), (i2,j2,k2), ...,(in,jn.kn))


Can anyone give me some advice on how to achieve this ? I got a little
idea, but still need to keep working til i get it. Thanks in advance,


Victor
 
C

cokofreedom

a = 1, 2
b = 3, 4, 5
c = 6, 7, 8, 9
coord = list()

for i, j, k in zip(a, b, c):
coord.append((i, j, k))

print coord
 
A

alex23

Hi,

i am using a software which uses python as its scripting language. I
want to generate a list of coordinates more or less this way:

for i in (beg, end, step):
for j in (beg, end, step):
for k in (beg, end, step):
.........

Coords = ((i1,j1,k1), (i2,j2,k2), ...,(in,jn.kn))

Can anyone give me some advice on how to achieve this ? I got a little
idea, but still need to keep working til i get it. Thanks in advance,

Victor
coords = [(x,y,z) for x in range(0,10) for y in range(0,10) for z in range(0,10)]
 
G

Gary Herron

Hi,

i am using a software which uses python as its scripting language. I
want to generate a list of coordinates more or less this way:

for i in (beg, end, step):
for j in (beg, end, step):
for k in (beg, end, step):
.........

Coords = ((i1,j1,k1), (i2,j2,k2), ...,(in,jn.kn))

Your statement of the problem makes it look like all three coordinates
cover the same sequence of values. Is that true? Or does i's range
(beg, end, step) differ from j's and k's. If they differ, are they
all the same length?

You pseudo-code makes it look like you want all combinations, but your
sample output does not indicate that. Which is it, [(1,1,1), (2,2,2)]
or [(1,1,1), (1,1,2),(1,2,1),(1,2,2), ...]?

Depending on the answers to those questions, one of the following list
comprehensions may demonstrate how to achieve a solution.
>>> a = range(2,6,2)
>>> b = range(3,7,2)
>>> c = range(10,14,2)
>>> print a,b,c [2, 4] [3, 5] [10, 12]
>>> [(i,j,k) for i,j,k in zip(a,b,c)] # Using zip process three lists
in lock-step
[(2, 3, 10), (4, 5, 12)]
>>> [(i,j,k) for i in a for j in b for k in c] #Nested loop give
all possible combos.
[(2, 3, 10), (2, 3, 12), (2, 5, 10), (2, 5, 12), (4, 3, 10), (4, 3, 12),
(4, 5, 10), (4, 5, 12)]
Gary Herron
 
V

victor.herasme

i am using a software which uses python as its scripting language. I
want to generate a list of coordinates more or less this way:
for i in (beg, end, step):
     for j in (beg, end, step):
          for k in (beg, end, step):
.........
Coords =  ((i1,j1,k1), (i2,j2,k2), ...,(in,jn.kn))

Your statement of the problem makes it look like all three coordinates
cover the same sequence of values.  Is that true? Or does i's range  
(beg, end, step) differ from j's and k's.    If they differ, are they
all the same length?

You pseudo-code makes it look like you want all combinations, but your
sample output does not indicate that.  Which is it, [(1,1,1), (2,2,2)]
or [(1,1,1), (1,1,2),(1,2,1),(1,2,2), ...]?

Depending on the answers to those questions, one of the following list
comprehensions may demonstrate how to achieve a solution.

 >>> a = range(2,6,2)
 >>> b = range(3,7,2)
 >>> c = range(10,14,2)
 >>> print a,b,c
[2, 4] [3, 5] [10, 12]
 >>> [(i,j,k) for i,j,k in zip(a,b,c)]  #  Using zip process three lists
in lock-step
[(2, 3, 10), (4, 5, 12)]
 >>> [(i,j,k) for i in a  for j in b  for k in c]   #Nested loop give
all possible combos.
[(2, 3, 10), (2, 3, 12), (2, 5, 10), (2, 5, 12), (4, 3, 10), (4, 3, 12),
(4, 5, 10), (4, 5, 12)]
 >>>

Gary Herron




Can anyone give me some advice on how to achieve this ? I got a little
idea, but still need to keep working til i get it. Thanks in advance,

- Mostrar texto de la cita -

Hi ,

i have another question. What if i wanted to make n tuples, each with
a list of coordinates. For example :


coords = list()
for h in xrange(1,11,1):
for i in xrange(1, 5, 1) :
for j in xrange(1, 5, 1) :
for k in xrange(1,2,1) :
coords.append((i,j,k))
lista+str(h)= tuple coords
print tuple(coords)


so that i will have tuple1, tuple2,..., tupleN, etc. I am trying to do
it the way i show you above but it is not working properly. I wish you
could help me with that. Thanks again,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,271
Latest member
BuyAtenaLabsCBD

Latest Threads

Top