Create 3D array using Python

前端 未结 9 1212
情话喂你
情话喂你 2020-12-23 09:57

I would like to create a 3D array in Python (2.7) to use like this:

distance[i][j][k]

And the sizes of the array should be the size of a vari

9条回答
  •  忘掉有多难
    2020-12-23 10:15

    d3 = [[[0 for col in range(4)]for row in range(4)] for x in range(6)]
    
    d3[1][2][1]  = 144
    
    d3[4][3][0]  = 3.12
    
    for x in range(len(d3)):
        print d3[x]
    
    
    
    [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    [[0, 0, 0, 0], [0, 0, 0, 0], [0, 144, 0, 0], [0, 0, 0, 0]]
    [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [3.12, 0, 0, 0]]
    [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
    

提交回复
热议问题