python - 将元组中的列表转换为numpy数组?

标签 python arrays numpy scipy tuples

我有列表元组。这些列表之一是分数列表。我想将分数列表转换为 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/

相关文章:

python - TensorFLow:tf.contrib.rnn 模块对象不可调用

python - 一个傅里叶如何变换 1's and 0' 的数组

c - 大数组在 C 中给出段错误

python - 修改神经网络对单个示例进行分类

python - 使用 win32com 设置属性

python - 什么时候应该使用 "if"检查错误,什么时候应该使用异常?

javascript - 反转动态数组

python - 矩阵行组合的生成

python - 坚持实现简单的神经网络

python - 使用条件从集合中弹出一个值