我想将下面的列表更改为二维数组。列表/数组形状经常让我感到困惑,我希望数据格式为 y=14.96,22.17,... 和 x=15.25,25.36,... Final_array = [x,y],这样会更容易绘制。
[[14.96786030991488, 15.26],
[22.170739257927302, 25.366999999999997],
[32.07129009546086, 39.536000000000001],
[53.91092877753442, 59.655000000000001],
[90.1398030963187, 89.387],
[117.33864311518501, 119.70999999999999],
[123.99886910884739, 155.13999999999999],
[220.35978335270883, 241.97],
[246.1408069941774, 281.25],
[275.5098457739598, 312.33999999999997],
[326.2608566528128, 365.13],
[399.24680126783164, 415.20999999999998]]
到目前为止已经尝试过:
np.reshape(mean_plain,[12,2])
最佳答案
您需要转置将元组映射到列表的原始列表列表:
l = list(map(list,zip(*l)))
如果您使用 numpy,只需创建一个数组:
l = np.array(list(map(list,zip(*l))))
您想要的形状是 2, 12
,这正是在压缩列表上调用 array 将为您提供的形状。
关于python - 在 Python 中 reshape 附加列表 - 将列表拆分为列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33109002/