Convert list in tuple to numpy array?

ぃ、小莉子 提交于 2019-11-30 22:36:08

问题


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?


回答1:


The command numpy.asarray will turn a number of pre-set iterable containers (list, tuple, etc) into a numpy array.



来源:https://stackoverflow.com/questions/2402575/convert-list-in-tuple-to-numpy-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!