如何将数组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矩阵。
答案 0 :(得分: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]])