Python - Multi-Dimensional Arrays

c, python

Solution

With so many dimensions, and no library imports allowed, I'd go (as the basic choice) for a dictionary indexed by tuples. This way, you get very nice syntax for simple indexing:

Array = dict()
Array[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] = [1.0, 0.0, 0.0]

You'll probably want to wrap it in a class to add functionality beyond simple indexing, but, not knowing what it is that you want beyond that (initialization/defaults? slicing? iteration? etc, etc...), it's just too hard to guess. If you can specify precisely all that you want to do with that "multi-dimensional array", it shouldn't be hard to show you the code that best provides it!

Problem

Python does not provide built-in support for multi-dimensional arrays. I need to develop an 11-dimensional array and a set of functions to operate on it (mostly linear algebra, vector arithmetics). However, no external library import is allowed. I have a code in C and trying to port it to Python: ``` typedef vec3_t float[3]; vec3_t Array[dim0][dim1][dim2][dim3][dim4][dim5][dim6][dim7][dim8][dim9][dim10]; Array[0][0][0][0][0][0][0][0][0][0][1] = {1.0, 0.0, 0.0}; ``` How can it be implemented in Python effectively (with good readability)? PS: For Python 2.5 version at most.

Original source