将元组中的列表转换为numpy数组?
问题描述:
我有列表的元组.这些列表之一是分数列表.我想将分数列表转换为numpy数组,以利用scipy提供的预先构建的统计信息.
I have tuple of lists. One of these lists is a list of scores. I want to convert the list of scores to a numpy array to take advantage of the pre-built stats that scipy provides.
在这种情况下,元组称为数据"
In this case the tuple is called 'data'
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
一旦存储了元组,我可以轻松地做到这一点吗?
Can I do this easily once I have stored the tuple?
答
命令 numpy.asarray
会将许多预设的可迭代容器(列表,元组等)转换为numpy数组.
The command numpy.asarray
will turn a number of pre-set iterable containers (list, tuple, etc) into a numpy array.