faqts : Computers : Programming : Languages : Python : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 4 people (25%) answered Yes
Recently 0 of 2 people (0%) answered Yes

Entry

How can I hold x,y,z coordinates in a multi-level grid?

Jul 25th, 2000 03:54
unknown unknown, Peter Schneider-Kamp


You can use lists of lists of lists of 3-tuples containing the 
coordinates. Adressing is done via repeated indexing.
For example the corners of a unit cube between 0 and 1:
>>> a = [ [ [(0,0,0), (0,0,1)], [(0,1,0), (0,1,1)] ],
...       [ [(1,0,0), (1,0,1)], [(1,1,0), (1,1,1)] ] ]
>>> a[0][0][0]
(0, 0, 0)
>>> a[1][0][1]
(1, 0, 1)
>>>
You can also use NumPy. Chances are (if only slight ones) that it will 
be included with 2.0
(see PEP 206 http://python.sourceforge.net/peps/pep-0206.html)