我有一个具有以下外观的列表:
[0] = [ [0.0, 100.0], [0.1, 93.08], [0.3, 92.85], [0.5, 92.62], [0.7, 91.12], [0.9, 90.89] ]
[1] = [ [0.0, 100.0], [0.1, 2.79], [0.3, 2.62], [0.5, 2.21], [0.7, 1.83], [0.9, 1.83] ]
我想获得向量来绘制信息,如下所示:
[0.0, 0.1, 0.3, 0.5, 0.7, 0.9]
[100.0, 93.08, 92.85, 92.62, 91.12, 90.89]
列表中的所有条目也是如此。
我正在尝试类似的东西:
x = mylist[0][:][0]
有任何想法吗?我感谢您的帮助!
最佳答案
使用 zip
:
>>> mylist = [
[0.0, 100.0], [0.1, 93.08], [0.3, 92.85], [0.5, 92.62],
[0.7, 91.12], [0.9, 90.89] ]
>>> a, b = zip(*mylist)
>>> a
(0.0, 0.1, 0.3, 0.5, 0.7, 0.9)
>>> b
(100.0, 93.08, 92.85, 92.62, 91.12, 90.89)
>>> list(a)
[0.0, 0.1, 0.3, 0.5, 0.7, 0.9]
>>> list(b)
[100.0, 93.08, 92.85, 92.62, 91.12, 90.89]