Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将数组a = [[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]]转换为形式的 numpy 矩阵
a = [[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]]
[[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]]
? 我试过np.bmat(a)无济于事。当我这样做时,我得到一个 2x6 矩阵。
np.bmat(a)
用于np.array构造数组,然后reshape将其塑造成正确的形状:
np.array
reshape
>>> np.array([[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]]).reshape((4,4)) array([[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12], [13, 14, 15, 16]])