小编TJa*_*ain的帖子

如何在远程计算机上保存实时数据的图?

我想通过sshing和检查图来了解我的模型在训练时的表现(即实时数据方式).

animation.FuncAnimation每次在我的本地机器上更新时,使用我能够保存(和覆盖)一个帧,如下所示:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

def animate(i):
    fig.clf()

    plt.suptitle('Title here')

    # actually parse model outputs and plot
    values = np.random.random_integers(0, 100, (100,))
    plt.plot(np.arange(len(values)), values, label='random')
    plt.ylabel('demo data')
    plt.grid()


    plt.legend()
    plt.xlabel('Epochs')
    fig.savefig('Figure.png')


fig = plt.figure()
ani = animation.FuncAnimation(fig, animate, interval=10*60*1000)
plt.show()
Run Code Online (Sandbox Code Playgroud)

在本地机器上使用它很好,因为plt.show调用$ DISPLAY.但是,当在远程服务器上运行时(ssh当然是通过),因为没有显示,我得到了RuntimeError: Invalid DISPLAY variable.当使用像svgvia 这样的其他后端时matplotlib.use('svg').脚本退出而不实际保存任何图像.

另外,我决定在函数中使用plt.show()fig.savefig('Figure.png')内部animate是因为在plt.show()调用之后没有函数FuncAnimation,它不会运行animate给定的间隔.我尝试过做plt.savefig …

python matplotlib

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

邻接矩阵的BFS

我正在尝试在无向未加权图的邻接矩阵上实现BFS,该矩阵返回所访问的节点数.到目前为止,我已经想出了这个,但我认为这是不对的,因为当我打印出top/visited节点时,我会多次出现一些节点,而且它没有排序.我已经读过BFS是拓扑排序的地方,我得到的顺序没有排序.

int BFS(std::vector<std::vector<int> > &matrix, int start)
{
    std::vector<bool> visited(matrix.size(), false);
    std::queue<int> Q;
    Q.push(start);
    int count = 0;

    while( ! Q.empty())
    {
        int top = Q.front(); Q.pop();
        visited[top] = true; count++;
        for (int i = 0; i < matrix.size(); ++i)
        {
            if(matrix[top][i] != 0 && (! visited[i]) )
            {
                Q.push(i);
            }
        }
    }
    return count;
}
Run Code Online (Sandbox Code Playgroud)

c++ breadth-first-search

6
推荐指数
2
解决办法
9439
查看次数

在Python中读取大量的json文件?

这不是关于读取大型JSON文件,而是以最有效的方式读取大量JSON文件.

我正在使用Million歌曲数据集中的last.fm数据.数据以一组JSON编码的文本文件的形式提供,其中的键是:track_id,artist,title,timestamp,similars和tags.

目前,我读他们到下列方式大熊猫经历几个选项,因为这是最快的,如图后在这里:

import os
import pandas as pd
try:
    import ujson as json
except ImportError:
    try:
        import simplejson as json
    except ImportError:
        import json


# Path to the dataset
path = "../lastfm_train/"

# Getting list of all json files in dataset
all_files = [os.path.join(root,file) for root, dirs, files in os.walk(path) for file in files if file.endswith('.json')] 

data_list=[json.load(open(file)) for file in all_files]
df = pd.DataFrame(data_list, columns=['similars', 'track_id'])
df.set_index('track_id', inplace=True)
Run Code Online (Sandbox Code Playgroud)

当前方法读取子集(在不到一秒的时间内完整数据集的1%).然而,读满车组的速度太慢,永远需要(我已经等了几个小时也一样)来读取,并已成为如所示进一步任务的瓶颈问题在这里. …

python json pandas

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

C++中的字符串流,用于解析字符串和数字

我有这样的字符串:'123plus43times7'

其中数字后跟字典中的单词.

我知道我可以使用>>运算符提取int/numbers :

StringStream >> number
Run Code Online (Sandbox Code Playgroud)

我可以得到这个号码.但是,Stream仍然有数字.如果数字长度未知或者我应该找出数字的长度,然后使用str.substr()创建新的字符串流,如何删除该数字?使用C++ STL String和SStream执行此任何其他更好的方法将非常感激.

c++ string stringstream

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

删除所有列中具有相同值的行

我有一个熊猫数据框,我试图根据具有完全相同值的所有列删除行。这是一个帮助理解这个想法的例子。

输入:

index  A  B  C  D  E  F ....
 0     1  2  3  1  3  4
 1     2  2  2  2  2  2
 2     5  5  5  5  5  5 
 3     7  7  6  7  7  7
Run Code Online (Sandbox Code Playgroud)

输出:

index  A  B  C  D  E  F ....
 0     1  2  3  1  3  4
 3     7  7  6  7  7  7
Run Code Online (Sandbox Code Playgroud)

这里可以有很多列。

python dataframe pandas

2
推荐指数
2
解决办法
936
查看次数