3d array?

Tim Hochberg tim.hochberg at ieee.org
Fri Jan 19 09:05:00 EST 2001


"Dan Stromberg" <strombrg at seki.acs.uci.edu> wrote in message
> I love python, but is there really no good way of doing a 3d array of
> a scalar type?  How about of an aggregate type?

If you're working with numbers, check out Numeric Python (NumPy), it's what
you want. Trust me. If your working with more general data types, you're
probably better off using nested lists. For example:

a =  [[[1,2,3], [4,5,6], [7,8,9]],
        [[11,12,13], [14,15,16], [17,18,19]],
        [[21,22,23], [24,25,26], [27,28,29]]]

would give you a 3D "array" with lots of silly numbers in it. Elements would
be accessed using "A[1][2][0]", etc.

If you want to use prettier indexing, you could roll your own class using
__getitem__ and __setitem__. I was going to provide an example, but work is
intruding, so maybe later.

-tim






More information about the Python-list mailing list