python - 在 Python 中 reshape 附加列表 - 将列表拆分为列

标签 python list reshape

我想将下面的列表更改为二维数组。列表/数组形状经常让我感到困惑,我希望数据格式为 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/

相关文章:

python - Flask 邮件给出了 celery 的 Pickling 错误

python - 访问元组列表中的 y 坐标

python - flask 虚拟环境

matlab - MATLAB 中的广义按元素数组复制(每个元素按可变大小复制)

python - 在特定条件下在 python 中迭代 CSV 文件

python - 给定一个标记为 1 到 N 的列表 L,以及一个考虑随机元素 "removes"的过程,如何有效地跟踪 min(L)?

list - 作为参数传递的对象不是环境

python - python中的命名字典

arrays - reshape 和重新排列数组

python - 在 R 与 Python 中 reshape 数据