在Python中,我有一个像这样的列表:
array =
[[[0,0,1,0],[0,0,0,1],[1,0,0,0],[0,1,0,0]],
[[0,1,0],[1,0,0],[0,0,1],[0,0,1]],
[[0],[1],[0],[1]],
[[1],[1],[0],[1]]]
我想将其重塑为:
array =
[[[0,0,1,0],[0,1,0],[0],[1]],
[[0,0,0,0],[1,0,0],[1],[1]],
[[1,0,0,0],[0,0,1],[0],[0]],
[[0,1,0,0],[0,0,1],[0],[1]]]
有什么建议吗?
答案 0 :(得分:2)
IIUC,给定
array = [[[0,0,1,0],[0,0,0,1],[1,0,0,0],[0,1,0,0]],
[[0,1,0],[1,0,0],[0,0,1],[0,0,1]],
[[0],[1],[0],[1]],
[[1],[1],[0],[1]]]
做
import numpy as np
>>> np.array(array).T
array([[list([0, 0, 1, 0]), list([0, 1, 0]), list([0]), list([1])],
[list([0, 0, 0, 1]), list([1, 0, 0]), list([1]), list([1])],
[list([1, 0, 0, 0]), list([0, 0, 1]), list([0]), list([0])],
[list([0, 1, 0, 0]), list([0, 0, 1]), list([1]), list([1])]],