473,289 Members | 2,089 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,289 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 2087
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.