4

如何将数组a = [[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]]转换为形式的 numpy 矩阵

[[1,2,3,4],
[5,6,7,8],
[9,10,11,12],
[13,14,15,16]]

? 我试过np.bmat(a)无济于事。当我这样做时,我得到一个 2x6 矩阵。

4

1 回答 1

3

用于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]])
于 2012-10-22T01:00:06.520 回答