Multidimensional array in Python

前端 未结 12 1521
独厮守ぢ
独厮守ぢ 2021-02-04 15:49

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         


        
12条回答
  •  梦谈多话
    2021-02-04 16:25

    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.

提交回复
热议问题