小编Day*_*ira的帖子

如何使用numpy数组创建pydub AudioSegment?

我在python中有以下代码

from scipy.io.wavfile import read
rate, signal = read('./data/input.wav')
# get only one channel
signal = signal[:,0] 
# do a bunch of processing here
Run Code Online (Sandbox Code Playgroud)

现在我想使用'signal'和'rate'创建一个pydub段

audio_segment = pydub.AudioSegment()
Run Code Online (Sandbox Code Playgroud)

那么,如何创建该音频片段,之后又如何以numpy数组的形式获取信号呢?

python audio numpy scipy pydub

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

将正则表达式与可选的前瞻匹配

我有以下字符串:

NAME John Nash FROM California

NAME John Nash

我想要一个能够为两个字符串提取"John Nash"的正则表达式.

这是我试过的

"NAME(.*)(?:FROM)"
"NAME(.*)(?:FROM)?"
"NAME(.*?)(?:FROM)?"
Run Code Online (Sandbox Code Playgroud)

但这两个字符串都不起作用.

python regex regex-greedy regex-lookarounds

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

是否可以使用pdfquery的正则表达式?

我们可以使用正则表达式来检测pdf中的文本(使用pdfquery或其他工具)吗?

我知道我们可以这样做:

pdf = pdfquery.PDFQuery("tests/samples/IRS_1040A.pdf")
pdf.load()
label = pdf.pq('LTTextLineHorizontal:contains("Cash")')
left_corner = float(label.attr('x0'))
bottom_corner = float(label.attr('y0'))
cash = pdf.pq('LTTextLineHorizontal:in_bbox("%s, %s, %s, %s")' % \
        (left_corner, bottom_corner-30, \
        left_corner+150, bottom_corner)).text()
print cash
'179,000.00'
Run Code Online (Sandbox Code Playgroud)

但是我们需要这样的东西:

pdf = pdfquery.PDFQuery("tests/samples/IRS_1040A.pdf")
pdf.load()
label = pdf.pq('LTTextLineHorizontal:regex("\d{1,3}(?:,\d{3})*(?:\.\d{2})?")')
cash = str(label.attr('x0'))
print cash
'179,000.00'
Run Code Online (Sandbox Code Playgroud)

python regex pdfminer

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

如何在 matplotlib/seaborn 上设置带有 LaTex 符号的轴标签的字体大小?

在 matplotlib 中,如何更改乳胶符号的字体大小?

我有以下代码:

import matplotlib.pyplot as plt
import seaborn as sns

# get x and y from file

plt.plot(x, y,  linestyle='--', marker='o', color='b')
plt.xlabel(r'$\alpha$ (distance weighted)', fontsize='large')
plt.ylabel('AUC')
plt.show()
Run Code Online (Sandbox Code Playgroud)

但我得到以下图表:

在此输入图像描述

请注意,$\alpha$ 仍然很小。

python matplotlib seaborn

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

如何比较两个 sklearn 估计器是否相等?

我有两个 sklearn 估计器并想比较它们:

import numpy as np
from sklearn.tree import DecisionTreeClassifier

X, y = np.random.random((100,2)), np.random.choice(2,100)    
dt1 = DecisionTreeClassifier()
dt1.fit(X, y)
dt2 = DecisionTreeClassifier()
dt3 = sklearn.base.copy.deepcopy(dt1)
Run Code Online (Sandbox Code Playgroud)

如何比较分类器以便 dt1 != dt2, dt1 == dt3?

python scikit-learn

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

如何在Python中检测PDF文档中的旋转页面?

给定一个多页 PDF 文档,如何检查给定页面是否旋转(-90、90 或 180\xc2\xba)?最好使用 Python (pdfminer, pyPDF) ...

\n\n

更新:页面是扫描的,大部分页面都是由文本组成的。

\n

python pdf image-processing pypdf pdfminer

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

如何在python中获取平面图的外部轮廓?

获得平面图外部轮廓的最佳方法是什么?

在此处输入图片说明

Snakes算法效果不佳,因为某些平面图过于凸出。

opencv image-processing scikit-image

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

我无法使用 <search.h> 中的 sizeof(struct hsearch_data)

我正在开发一个开源项目,并且有一个 hash_table\n我需要将其更改为更高效的 hash_table,因此,我\n尝试使用 header <search.h>

\n\n

问题是我需要覆盖整个项目中已经使用的函数...但为此,我需要使用 sizeof(struct hsearch_data) 但它不起作用。

\n\n

按照代码:

\n\n
#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#define _GNU_SOURCE\n#include <search.h>\n#include "hashtable.h"\n\n#define MAX_ELEMENTS 100\n#define ERROR 2\n#define SUCCESS 0\n\nhash_table *new_hash_table()\n{\n    hash_table *table = (hash_table *) malloc(sizeof(struct hsearch_data));\n    *table = {0};   \n\n    int status = hcreate_r(MAX_ELEMENTS, table);\n\n    if (status == 0) {\n            hdestroy_r(table);\n            return NULL;\n    }\n\n    return table; \n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

PS:头文件中,有一个\n typedef struct hsearch_data hash_table;

\n\n

我收到错误消息:

\n\n
hashtable.c: In function \xe2\x80\x98new_hash_table\xe2\x80\x99:\nhashtable.c:18: error: invalid application of \xe2\x80\x98sizeof\xe2\x80\x99 to incomplete type \xe2\x80\x98struct hsearch_data\xe2\x80\x99 \nhashtable.c:19: …
Run Code Online (Sandbox Code Playgroud)

c search hashtable sizeof

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

C fcntl抽象函数不起作用

我正在写一个应用程序及其在规范中我需要在每次写入时锁定文件(此文件将被其他团队正在处理的其他应用程序读取):

我做了以下功能:

int lock_file (int fd)
{
    if (fd == -1)
        return -1;
    struct flock file_locker;
    file_locker.l_type = F_WRLCK;
    file_locker.l_whence = SEEK_SET;
    file_locker.l_start = 0;
    file_locker.l_len = 0; //lock the entire file

    int locked = fcntl(fd, F_SETLK, &file_locker);
    if (locked == -1){
        /*handle errors*/
        return 0;
    }
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

我可以获得1返回(意味着一切正常)但是当我做一个测试用例时,我可以写入锁定的文件Oo

测试代码是:

char *file = "lock_test_ok";
int fd = open(file, O_RDWR);
int locked = lock_file(fd);
/* call popen and try write 'ERROR' in the file */

/* if the file …
Run Code Online (Sandbox Code Playgroud)

c file-io locking popen fcntl

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