【发布时间】:2019-09-12 14:37:19
【问题描述】:
我想转换
编辑:下面的代码是列表的 3D 列表,
[
[
[
[1,2,3,],
[4,5,6,],
],
[
[7,8,9,],
[10,11,12,],
],
],
[
[
[A,B,C,],
[D,E,F,],
],
[
[G,H,I,],
[J,K,L,],
],
],
]
进入
[
[1,2,3],
[4,5,6],
[7,8,9],
[10,11,12],
[A,B,C],
[D,E,F],
[G,H,I],
[J,K,L]
]
我试过 numpy.flatten 但没有成功 https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flatten.html
【问题讨论】:
-
你试过
my_array.reshape(8, 3)吗? -
由于列表中有字符和数字,我建议使用 pandas 而不是 numpy
-
你想要什么
dtype?什么是A、B等。如图所示,这些是变量,而不是字符串。因此,它们必须具有值,在 Python 中可以是任何值。变量 id 不会显示在实际列表(或数组)中。
标签: python numpy reshape flatten