整数列表上的 CountVectorizer [英] CountVectorizer on list of integers

查看:51
本文介绍了整数列表上的 CountVectorizer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下整数列表:

<代码>mylist = [111,113,114,115,112,115,234,643,565,....]

我有很多这样的列表,其中包含超过 500 个整数,我想在这些列表上运行 CountVectorizer.据我所知,CountVectorizer 只标记字符串列表而不是整数.

I have many lists like this with more than 500 integers on which I wanted to run CountVectorizer. As far as I know, CountVectorizer only tokenize list of string than integers.

我尝试首先通过

<代码>mylist_string = list(map(lambda x: str(x), mylist))但由于列表太长,需要很长时间.

mylist_string = list(map(lambda x: str(x), mylist)) but since the list is too long, it is taking very large time.

有什么方法可以标记整数列表,或者有什么有效的方法可以将数字列表转换为字符串列表.

Is there any way to tokenize the integer lists or is there any efficient way to convert the list of numbers to list of strings.

谢谢

推荐答案

对于您的情况,将 map 与 lambda 一起使用是多余的,这可能是速度变慢的原因,你可以只使用 map 而没有 lambda,如下所示

For your case, its redundant to use map with lambda, that might be the reason for the slow down, you could just use map without lambda like below

mylist = [111,113,114,115,112,115,234,643,565]
mylist_string = map(str, mylist) # use list(map(str, mylist)) for python 3
# ['111', '113', '114', '115', '112', '115', '234', '643', '565']

或者,你可以试试list comprehension

mylist = [111,113,114,115,112,115,234,643,565]
mylist_string = [str(x) for x in mylist]
# ['111', '113', '114', '115', '112', '115', '234', '643', '565']

这篇关于整数列表上的 CountVectorizer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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