如下所示:
1
2
3
4
5
6
7
|
temp1 = [[] for i in range ( 10 )]
temp2 = [temp1 for i in range ( 20 )]
temp3 = [temp2 for i in range ( 30 )]
for i in range ( 30 ):
for j in range ( 20 ):
for k in range ( 10 ):
temp3[i][j][k] = 0
|
但是赋值的时候还是发现是指向同一地址的
所以还得这样
1
2
3
4
5
6
7
|
matrix3d = []
for i in range ( 30 ):
matrix3d.append([])
for j in range ( 20 ):
matrix3d[i].append([])
for k in range ( 10 ):
matrix3d[i][j].append( 0 )
|
以上这篇python 构造三维全零数组的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:原文链接:https://blog.csdn.net/guotong1988/article/details/71173319