小编Fed*_*cia的帖子

使用 python asyncio 的多个任务

我有以下代码:

import asyncio

async def test_1():      
    res1 = await foo1()
    return res1

async def test_2():      
    res2 = await foo2()
    return res2

if __name__ == '__main__':
    print(asyncio.get_event_loop().run_until_complete([test_1, test_2]))
Run Code Online (Sandbox Code Playgroud)

但最后一次调用.run_until_complete()不起作用。如何使用 对多个任务执行异步调用.run_until_complete()

python multithreading asynchronous python-3.x python-asyncio

7
推荐指数
1
解决办法
9794
查看次数

在线聚集新闻文章

是否有常用的在线算法对新闻进行动态分类?我有按主题分类的大量新闻数据集。我认为每个主题都是一个集群。现在,我需要对突发新闻进行分类。可能,我将需要动态生成新主题或新集群

我正在使用的算法如下:

1)我浏览了新闻站点的一组提要,并且识别了新闻链接。

2)对于每个新链接,我使用Dragnet提取内容,然后将其标记化。

3)我使用sklearn的TfidfVectorizer找到了所有旧新闻和最后一个新闻的向量表示。

4)我发现我的数据集中距离最近新闻向量表示和旧新闻的所有向量表示的欧几里德距离的最近邻居。

5)如果该距离小于阈值,则将其放入邻居所属的群集中。否则,我将使用突发新闻创建一个新的集群

每次收到新闻时,我都会使用TfidfVectorizer重新拟合所有数据,因为可以建立新的维度。我迫不及待地想每天重新安装一次,因为我需要检测可能与未知主题相关的突发事件。有没有一种比我使用的方法更有效的通用方法?

nlp information-retrieval cluster-analysis machine-learning unsupervised-learning

5
推荐指数
1
解决办法
199
查看次数

numpy isclose 函数返回错误答案吗?

在以下示例中使用 numpy isclose:

import numpy as np
np.isclose(1533761040,1533748023.0, atol=1)
Run Code Online (Sandbox Code Playgroud)

返回 True,返回 False。

python search numpy

1
推荐指数
1
解决办法
1500
查看次数

使用事务的 MongoDB 错误:所有事务操作的总大小必须小于 16793600。实际大小为 16793810:通用服务器错误

我正在使用 C++ 处理 mongodb 事务。我正在执行的步骤如下:

  1. 创建会话
  2. 为这个会话创建一个bulk_write,我有多个插入到一个集合中
  3. 开始交易
  4. 执行批量写入
  5. 提交事务

这是算法的代码片段:

#include <iostream>
#include <vector>

#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/exception/exception.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/exception/exception.hpp>
#include <mongocxx/exception/logic_error.hpp>
#include <mongocxx/exception/operation_exception.hpp>


int main(int argc, char** argv)
{
    /* Parameters */

    std::string db_uri = "<PROVIDE URI TO CONNECT WITH A MONGO DB WITH REPLICA SETS>";
    std::string db_name = "db_0";
    std::string collection0_name = "coll_0";
    int N_INSERTS = 100000;

    /* Init connection */

    static mongocxx::instance inst{};
    mongocxx::uri client_uri = mongocxx::uri(db_uri);
    mongocxx::options::client client_options;
    mongocxx::options::ssl …
Run Code Online (Sandbox Code Playgroud)

c++ mongodb mongo-cxx-driver

1
推荐指数
1
解决办法
968
查看次数