Create 3D array using Python

前端 未结 9 1195
情话喂你
情话喂你 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:17

    If you insist on everything initializing as empty, you need an extra set of brackets on the inside ([[]] instead of [], since this is "a list containing 1 empty list to be duplicated" as opposed to "a list containing nothing to duplicate"):

    distance=[[[[]]*n]*n]*n
    

提交回复
热议问题