WorldViz User Forum A Little Programming Problem with MultiDimensional Arrays
 User Name Remember Me? Password
 Register FAQ Search Today's Posts Mark Forums Read

#1
04-25-2007, 12:10 PM
 shivanangel Member Join Date: Feb 2006 Location: New Jersey Posts: 182
A Little Programming Problem with MultiDimensional Arrays

Hi everyone,

We are not perfectly versed in python and had a programming question to anyone out there who might be able to figure this out.

I want to create a 3 dimensional array of objects.

I have a class called Cone() which needs to be called and placed into an array of dimensions X,Y,Z.

I am having problems actually creating a loop that effectively goes through and does this for me.

Each time I try to do it, I end up with fewer cones, or the same instance of a cone in multiple spots in the array.

I've looked all over the web, and all the solutions I find show loops for 2 dimensional arrays, but nothing that extends to 3 dimensional ones.

Thank You,

George
#2
04-25-2007, 12:11 PM
 shivanangel Member Join Date: Feb 2006 Location: New Jersey Posts: 182
Sorry, in my previous post I kept calling it an 'array'
I meant - list.

Thanks,
George
#3
04-25-2007, 12:21 PM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
Hi,

Here is some code that creates an [X][Y][Z] dimensional list of Cone objects.
Code:
```class Cone(object): pass

X = 5
Y = 3
Z = 2

cones = [ [ [ Cone() for z in xrange(Z) ] for y in xrange(Y) ] for x in xrange(X) ]```
Hope this helps

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements Vizard Precision Position Tracker (PPT) Plug-in development

All times are GMT -7. The time now is 03:37 AM.

 Contact Us - WorldViz Home - Archive - Top