小编her*_*err的帖子

SED - 多行的正则表达式

我现在已经坚持了几个小时,并通过各种不同的工具循环来完成工作.没有成功.如果有人可以帮我解决这个问题,那真是太棒了.

这是问题所在:

我有一个非常大的CSV文件(400mb +)格式不正确.现在它看起来像这样:

This is a long abstract describing something. What follows is the tile for this sentence."   
,Title1  
This is another sentence that is running on one line. On the next line you can find the title.   
,Title2

你可能会看到标题",Title1"和",Title2"实际上应与前面的句子在同一行.然后它看起来像这样:

This is a long abstract describing something. What follows is the tile for this sentence.",Title1  
This is another sentence that is running on one line. On the next line you can find the title.,Title2

请注意,句子的结尾可以包含引号.最后,他们也应该被替换.

这是我到目前为止提出的:

sed -n '1h;1!H;${;g;s/\."?.*,//g;p;}' …
Run Code Online (Sandbox Code Playgroud)

regex csv bash sed

15
推荐指数
2
解决办法
4万
查看次数

将Ruby中的持续时间 - hh:mm:ss.sss转换为毫秒,反之亦然

我想知道Ruby中是否有内置方法允许我将hh:mm:ss.sss格式的单圈时间转换为毫秒,反之亦然.由于我需要对它进行一些计算,我认为转换为毫秒是最简单的方法.告诉我,如果我错了:)

ruby time

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

计算平方欧氏距离的可能优化

我需要在Python项目中每天进行几亿次欧氏距离计算.

这是我开始的:

def euclidean_dist_square(x, y):
    diff = np.array(x) - np.array(y)
    return np.dot(diff, diff)
Run Code Online (Sandbox Code Playgroud)

这是非常快的,我已经放弃了sqrt计算,因为我只需要对项目进行排名(最近邻搜索).尽管如此,它仍然是剧本的瓶颈.因此我编写了一个C扩展,用于计算距离.始终使用128维向量进行计算.

#include "euclidean.h"
#include <math.h>

double euclidean(double x[128], double y[128])
{
    double Sum;
    for(int i=0;i<128;i++)
    {
        Sum = Sum + pow((x[i]-y[i]),2.0);
    }
    return Sum;
}
Run Code Online (Sandbox Code Playgroud)

扩展的完整代码如下:https://gist.github.com/herrbuerger/bd63b73f3c5cf1cd51de

现在,与numpy版本相比,这提供了一个很好的加速.

但有没有办法进一步加快这一点(这是我的第一个C扩展,所以我假设有)?随着每天使用此功能的次数,每微秒实际上将提供一个好处.

你们中的一些人可能会建议将这完全从Python移植到另一种语言,不幸的是,这是一个更大的项目而不是一个选项:(

谢谢.

编辑

我在CodeReview上发布了这个问题:https://codereview.stackexchange.com/questions/52218/possible-optimizations-for-calculating-squared-euclidean-distance

如果有人开始写答案,我会在一小时内删除这个问题.

c python performance numpy

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

在 Linux 上重命名数百万个文件

我需要重命名大约 200 万张图像。这些文件看起来像这样image.jpg?arg=value,需要重命名为image.jpg不带参数。

这是我目前正在做的事情:

sudo find . -name "*.jpg?*" -exec rename 's/(\?.*)//' {} \;
Run Code Online (Sandbox Code Playgroud)

这完成了工作,但似乎需要很长时间。有人对如何加快速度有建议吗?

linux rename

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

标签 统计

bash ×1

c ×1

csv ×1

linux ×1

numpy ×1

performance ×1

python ×1

regex ×1

rename ×1

ruby ×1

sed ×1

time ×1