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.l
I've just stepped into a similar need and coded this:
def nDimensionsMatrix(dims, elem_count, ptr=[]):
if (dims > 1):
for i in range(elem_count[dims-1]):
empty = []
ptr.append(empty)
nDimensionsMatrix(dims-1, elem_count, empty)
return ptr
elif dims == 1:
ptr.extend([0 for i in range(elem_count[dims])])
return ptr
matrix = nDimensionsMatrix(3, (2,2,2))
I'm not looking at speed, only funcionality ;)
I want to create a matrix with N dimensions and initialize with 0 (a elem_count number of elements in each dimension).
Hope its helps someone