小编Meh*_*edB的帖子

如何根据 Numpy 风格的文档字符串记录 kwargs?

因此,我找到了与其他样式相关的帖子,并且我知道有关文档的 NumPy 页面,但我很困惑我不明白如何将每个 kwargs 添加到方法的参数部分。这是来自给定的网页:

def foo(var1, var2, *args, long_var_name='hi', **kwargs):
    r"""Summarize the function in one line.

    Several sentences providing an extended description. Refer to
    variables using back-ticks, e.g. `var`.

    Parameters
    ----------
    var1 : array_like
        Array_like means all those objects -- lists, nested lists, etc. --
        that can be converted to an array.  We can also refer to
        variables like `var1`.
    var2 : int
        The type above can either refer to an actual Python type
        (e.g. ``int``), or …
Run Code Online (Sandbox Code Playgroud)

python numpy docstring python-3.x

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

如何在没有终端或多处理库的情况下限制 python 脚本使用的 CPU 数量?

我的主要问题是在这里发布。由于还没有人给出解决方案,我决定找到一种解决方法。我正在寻找一种使用python 代码限制 python 脚本 CPU 使用率(不是优先级,而是 CPU 内核数)的方法。我知道我可以使用多处理库(池等)来做到这一点,但我不是使用多处理运行它的人。所以,我不知道该怎么做。而且我也可以通过终端来做到这一点,但是这个脚本是由另一个脚本导入的。不幸的是,我没有通过终端调用它的奢侈。

tl; dr:如何限制由另一个脚本导入的 python 脚本的CPU 使用率(核心数),我什至不知道为什么它并行运行,而不是通过终端运行它。请检查下面的代码片段。

导致问题的代码片段:

from sklearn.datasets import load_digits
from sklearn.decomposition import IncrementalPCA
import numpy as np

X, _ = load_digits(return_X_y=True)

#Copy-paste and increase the size of the dataset to see the behavior at htop.
for _ in range(8):
    X = np.vstack((X, X))

print(X.shape)

transformer = IncrementalPCA(n_components=7, batch_size=200)

#PARTIAL FIT RUNS IN PARALLEL! GOD WHY?
---------------------------------------
transformer.partial_fit(X[:100, :])
---------------------------------------
X_transformed = transformer.fit_transform(X)

print(X_transformed.shape)
Run Code Online (Sandbox Code Playgroud)

版本:

  • 蟒蛇 …

python unix multiprocessing python-3.x python-multiprocessing

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

从 Python 3 中的给定字符串解析测量值(多维)

我知道这篇文章这个库,但他们没有帮助我解决下面的这些具体案例。我如何解析如下测量值:

我有如下字符串;

"Square 10 x 3 x 5 mm"
"Round 23/22; 24,9 x 12,2 x 12,3"
"Square 10x2"
"Straight 10x2mm"
Run Code Online (Sandbox Code Playgroud)

我正在寻找一个 Python 包或某种方式来获得如下结果;

>>> a = amazing_parser.parse("Square 10 x 3 x 5 mm")
>>> print(a)
10 x 3 x 5 mm
Run Code Online (Sandbox Code Playgroud)

同样地;

>>> a = amazing_parser.parse("Round 23/22; 24,9x12,2")
>>> print(a)
24,9 x 12,2
Run Code Online (Sandbox Code Playgroud)

我还尝试使用“ner_ontonotes_bert_mult”模型使用“命名实体识别”。但结果如下:

>>> from deeppavlov import configs, build_model
>>> ner_model = build_model(configs.ner.ner_ontonotes_bert_mult, download=True)
>>> print(ner_model(["Round 23/22; 24,9 x 12,2 x 12,3"]))
<class …
Run Code Online (Sandbox Code Playgroud)

regex parsing units-of-measurement python-3.x ner

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