Alex Rivera | Logout

Multidimensional array in Python

Asked 2009-02-03T19:54:37.720
11

I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like:

double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;

Further values will be created bei loops and written into the array.

How do I instantiate the array?

PS: There is no matrix multiplication involved...

Edit
Report

1 Answer

0

Another option is to use a dictionary:

>>> from collections import defaultdict
>>> array = defaultdict(int) # replace int with the default-factory you want
>>> array[(0,0)]
0
>>> array[(99,99)]
0

You'll need to keep track of the upper & lower bounds as well.

answered 2008-11-05T07:33:36.687

Your Answer