473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Tuple of coordinates

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
Jun 27 '08 #1
4 2092
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
Jun 27 '08 #2
On May 29, 10:16 pm, "victor.hera...@gmail.com"
<victor.hera...@gmail.comwrote:
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)]
Jun 27 '08 #3
vi************@gmail.com wrote:
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
>
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
--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #4
On 29 mayo, 17:45, Gary Herron <gher...@islandtraining.comwrote:
victor.hera...@gmail.com wrote:
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


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
--
http://mail.python.org/mailman/listinfo/python-list- Ocultar texto de la cita -

- 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,
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Yomanium Yoth Taripoät II | last post by:
HI, 1) what are the differences between list and tuple? 2) how to concatenate tuple and list? no method, no opérator? 3) im looking the fucking manual, and cant add value in my tuple, when it...
3
by: steve | last post by:
Hi All I have textboxes within a TableLayoutpanel and I want to be able to position an independant control adjacent to a selected textbox This independent control allows selection of text to...
77
by: Nick Maclaren | last post by:
Why doesn't the tuple type have an index method? It seems such a bizarre restriction that there must be some reason for it. Yes, I know it's a fairly rare requirement. Regards, Nick...
0
by: raylopez99 | last post by:
keywords: logical coordinates, page coordinates, world coordinates, device coordinates, physical coordinates, screen coordinates, client coordinates. offset rectangle. WYSIWYG rubber rectangle...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.