我希望celery任务能够获取执行它的工作人员的名字,以便进行日志记录.我需要在任务中处理这个问题,而不是直接查询代理.有没有办法做到这一点?我正在使用芹菜和RabbitMQ,如果这很重要的话.
我想在基于文本语料库的scikit-learn 中创建一个 CountVectorizer,然后稍后将更多文本添加到 CountVectorizer(添加到原始字典)。
如果我使用transform(),它会保留原始词汇,但不会添加新词。如果我使用fit_transform(),它只会从头开始重新生成词汇表。见下文:
In [2]: count_vect = CountVectorizer()
In [3]: count_vect.fit_transform(["This is a test"])
Out[3]:
<1x3 sparse matrix of type '<type 'numpy.int64'>'
with 3 stored elements in Compressed Sparse Row format>
In [4]: count_vect.vocabulary_
Out[4]: {u'is': 0, u'test': 1, u'this': 2}
In [5]: count_vect.transform(["This not is a test"])
Out[5]:
<1x3 sparse matrix of type '<type 'numpy.int64'>'
with 3 stored elements in Compressed Sparse Row format>
In [6]: count_vect.vocabulary_
Out[6]: {u'is': 0, u'test': …Run Code Online (Sandbox Code Playgroud) 我在Python 2.6,a和b中有两个非常大的列表(比如50,000个字符串).
这有两个选择.哪个更快,为什么?有没有更好的办法?
c = [i for i in a if i not in b]
Run Code Online (Sandbox Code Playgroud)
要么...
c = list(a) # I need to preserve a for future use, so this makes a copy
for x in b:
c.remove(x)
Run Code Online (Sandbox Code Playgroud)