WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   A Little Programming Problem with MultiDimensional Arrays (https://forum.worldviz.com/showthread.php?t=1059)

shivanangel 04-25-2007 12:10 PM

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

shivanangel 04-25-2007 12:11 PM

Sorry, in my previous post I kept calling it an 'array'
I meant - list.

Thanks,
George

farshizzo 04-25-2007 12:21 PM

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


All times are GMT -7. The time now is 01:38 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC