Multidimensional array in Python

前端 未结 12 1528
独厮守ぢ
独厮守ぢ 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:06

    If you are OK using sparse arrays, you could use a dict to store your values. Python's dicts allow you to use tuples as keys, as such, you could assign to and access elements of the "sparse array" (which is really a dict here) like this:

    d = {}
    d[0,2,7] = 123 # assign 123 to x=0, y=2, z=7
    v = d[0,2,7]
    

提交回复
热议问题