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

时间:2010-03-08 15:53:38

标签: 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

存储元组后,我可以轻松完成此操作吗?

1 个答案:

答案 0 :(得分:43)

命令numpy.asarray会将许多预先设定的可迭代容器(列表,元组等)转换为numpy数组。