将元组中的列表转换为numpy数组? [英] Convert list in tuple to numpy array?

查看:911
本文介绍了将元组中的列表转换为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.

这篇关于将元组中的列表转换为numpy数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆