我想做一个像这样的三维数组:
treedarray = [[[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]]]
在该表中,每个值都可以通过使用(轻松)访问
treedarray [a] [b] [c]
我想知道是否有更容易做到这一点的命令。
提前谢谢。
使用Numpy和Numpy.zeros()可以定义以值列表作为第一个参数的形状。例如
import numpy as np
treedarray = np.zeros([3,3,3])
print treedarray
输出:
[[[ 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.]]]
并且可以使用treedarray[a][b][c]
访问伪值。