我试图创建一个结构为8x8的数组数组,其中每个单元格都是一个3x3数组。我所创建的工作,但当我想要改变一个特定的价值,我需要访问它不同于我的预期。
import numpy as np
a = np.zeros((3,3))
b = np.array([[0,1,0],[1,1,1],[0,1,0]])
d = np.array([[b,a,b,a,b,a,b,a]])
e = np.array([[a,b,a,b,a,b,a,b]])
g = np.array([[d],[e],[d],[e],[d],[e],[d],[e]])
#Needed to change a specific cell
#g[0][0][0][0][0][0] = x : [Row-x][0][0][Cell-x][row-x][cell-x]
#Not sure why I have to have the 2 0's between the Row-x and the Cell-x identifiers在此之后,我将需要将每个值映射到一个24x24网格,其中1的颜色与0的颜色不同。如果有人能够提供实现这一目标的方向,我们将不胜感激。不是寻找特定的代码,而是了解如何实现它的基础。
谢谢
发布于 2019-10-23 18:03:16
In [291]: a = np.zeros((3,3))
...: b = np.array([[0,1,0],[1,1,1],[0,1,0]])
...: d = np.array([[b,a,b,a,b,a,b,a]])
...: e = np.array([[a,b,a,b,a,b,a,b]])
...: g = np.array([[d],[e],[d],[e],[d],[e],[d],[e]])
In [292]: a.shape
Out[292]: (3, 3)
In [293]: b.shape
Out[293]: (3, 3)d是4d -计算括号:[[....]]
In [294]: d.shape
Out[294]: (1, 8, 3, 3)
In [295]: e.shape
Out[295]: (1, 8, 3, 3)g是(8,1)四个模糊元素,总共有6个。再次计算括号:
In [296]: g.shape
Out[296]: (8, 1, 1, 8, 3, 3)访问2d子数组,在本例中等于b
In [298]: g[0,0,0,0,:,:]
Out[298]:
array([[0., 1., 0.],
[1., 1., 1.],
[0., 1., 0.]])重做,去掉多余的括号:
In [299]: a = np.zeros((3,3))
...: b = np.array([[0,1,0],[1,1,1],[0,1,0]])
...: d = np.array([b,a,b,a,b,a,b,a])
...: e = np.array([a,b,a,b,a,b,a,b])
...: g = np.array([d,e,d,e,d,e,d,e])
In [300]: d.shape
Out[300]: (8, 3, 3)
In [301]: g.shape
Out[301]: (8, 8, 3, 3)https://stackoverflow.com/questions/58528385
复制相似问题