Multidimensional array in Python

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

    Take a look at numpy

    here's a code snippet for you

    import numpy as npy
    
    d = npy.zeros((len(x)+1, len(y)+1, len(x)+len(y)+3))
    d[0][0][0] = 0 # although this is unnecessary since zeros initialises to zero
    d[i][j][k] = npy.inf
    

    I don't think you need to be implementing a scientific application to justify the use of numpy. It is faster and more flexible and you can store pretty much anything. Given that I think it is probably better to try and justify not using it. There are legitimate reasons, but it adds a great deal and costs very little so it deserves consideration.

    P.S. Are your array lengths right? It looks like a pretty peculiar shaped matrix...

提交回复
热议问题