我有列表元组。这些列表之一是分数列表。我想将分数列表转换为 numpy 数组,以利用 scipy 提供的预构建统计信息。
在这种情况下,元组称为“数据”
In [12]: type data[2]
-------> type(data[2])
Out[12]: <type 'list'>
In [13]: type data[2][1]
-------> type(data[2][1])
Out[13]: <type 'list'>
In [14]: type data[2][1][1]
-------> type(data[2][1][1])
Out[14]: <type 'float'>
In [15]: print data[2][1]
-------> print(data[2][1])
[16.66, 16.66, 16.66, 16.66, 5.5599999999999996, 16.699999999999999]
In [16]: print data[2][1][1]
-------> print(data[2][1][1])
16.66
存储元组后,我可以轻松做到这一点吗?
最佳答案
命令 numpy.asarray
会将一些预先设置的可迭代容器(列表、元组等)变成一个 numpy 数组。
关于python - 将元组中的列表转换为numpy数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2402575/