我正在尝试查看该pyproject.toml文件,但我陷入了这个简单的任务。考虑以下可选依赖项:
[project.optional-dependencies]
style = ["black", "codespell", "isort", "flake8"]
test = ["pytest", "pytest-cov"]
all = ["black", "codespell", "isort", "flake8", "pytest", "pytest-cov"]
Run Code Online (Sandbox Code Playgroud)
有没有办法避免复制/粘贴密钥中的所有可选依赖项all?all = style + test至少有办法做到吗?
我的程序:
# -*- coding: utf-8 -*-
import numpy as np
import itertools
from scipy.optimize import minimize
global width
width = 0.3
def time_builder(f, t0=0, tf=300):
return list(np.round(np.arange(t0, tf, 1/f*1000),3))
def duo_stim_overlap(t1, t2):
"""
Function taking 2 timelines build by time_builder function in input
and returning the ids of overlapping pulses between the 2.
len(t1) < len(t2)
"""
pulse_id_t1 = [x for x in range(len(t1)) for y in range(len(t2)) if abs(t1[x] - t2[y]) < width]
pulse_id_t2 = [x for x in …Run Code Online (Sandbox Code Playgroud) 我有一个程序使用多处理库来计算一些东西。大约有 10K 个输入需要计算,每个输入需要 0.2 秒到 10 秒。
我目前的方法使用一个池:
# Inputs
signals = [list(s) for s in itertools.combinations_with_replacement(possible_inputs, 3)]
# Compute
with mp.Pool(processes = N) as p:
p.starmap(compute_solutions, [(s, t0, tf, folder) for s in signals])
print (" | Computation done.")
Run Code Online (Sandbox Code Playgroud)
我注意到在要检查的最后 300 / 400 个输入中,程序变慢了很多。我的问题是: thePool和 thestarmap()表现如何?
根据我的观察,我相信如果我有 10K 个输入和N = 4(4 个进程),那么 2 500 个第一个输入被分配给第一个进程,第二个旁边的 2 500 个,......每个进程都将其输入处理为连环时尚。这意味着如果某些进程在其他进程之前清除了队列,则它们不会执行新任务。
这样对吗?
如果这是正确的,我怎样才能拥有一个可以用这个伪代码表示的更智能的系统:
workers = Initialize N workers
tasks = A list of the tasks to …Run Code Online (Sandbox Code Playgroud) 我有以下设置:一个函数返回一个具有相同大小(100k 点)的 N 个时间线的字典。字典返回看起来像:
timelines = dict()
timelines["Name1"] = dict()
timelines["Name1"]["Name2"] = dict()
timelines["Name1"]["Name3"] = dict()
timelines["Name1"]["Name2"]["a"] = # List of 100k points
timelines["Name1"]["Name2"]["b"] = # List of 100k points
timelines["Name1"]["Name2"]["c"] = # List of 100k points
timelines["Name1"]["Name3"]["b"] = # List of 100k points
timelines["Name1"]["Name2"]["c"] = # List of 100k points
timelines["Name1"]["a"] = # List of 100k points
timelines["Name1"]["b"] = # List of 100k points
timelines["Name2"] # and so on.
Run Code Online (Sandbox Code Playgroud)
您可能已经理解,时间线(点列表)并不总是存储在同一级别中。有时我可以用 1 个键访问它,有时用 2 个,有时用 5 个。这些键会给我情节的标签,是必要的。我的计划是将一个键元组传递给 plot 函数。
例子: …
我有一个坏习惯,就是在文件夹/文件名中添加空格。今天它咬我了。
我有一个名为NFB LabNFB Lab 的文件夹。我想将快捷方式/命令 nfb 和 pynfb 添加到文件中~/.zshrc,以便从任何地方启动主 python 脚本。
我~/.zshrc通过 nano 编辑了该文件:
alias nfb=/Users/mathieu/Documents/NFB\ Lab/pynfb/main.py
alias pynfb=/Users/mathieu/Documents/NFB\ Lab/pynfb/main.py
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
alias nfb="/Users/mathieu/Documents/NFB Lab/pynfb/main.py"
alias pynfb="/Users/mathieu/Documents/NFB Lab/pynfb/main.py"
Run Code Online (Sandbox Code Playgroud)
两者都不起作用,我总是得到:
zsh: no such file or directory: /Users/mathieu/Documents/NFB
Run Code Online (Sandbox Code Playgroud)
如何在不卸载/重新安装 NFB Lab 的情况下解决此问题?
让我们考虑以下最小示例:
class Dummy:
def __init__(self, v1, v2, v3):
self.v1 = v1
self.v2 = v2
self.v3 = v3
def __key(self):
return (self.v1, self.v2, self.v3)
def __hash__(self):
return hash(self.__key())
def __eq__(self, other):
""" == comparison method."""
return isinstance(self, type(other)) and self.__key() == other.__key()
def __ne__(self, other):
""" != comparison method."""
return not self.__eq__(self, other)
D1 = Dummy(1, 2, 3)
D2 = Dummy(1, 4, 5)
Run Code Online (Sandbox Code Playgroud)
如果我尝试的话D1 == D2,我会得到的False。但是,如果尝试D1 != D2,我会得到:
D1 != D2
Traceback (most recent call …Run Code Online (Sandbox Code Playgroud) python ×5
class ×1
dictionary ×1
equality ×1
macos ×1
optimization ×1
python-3.x ×1
scipy ×1
toml ×1
zsh ×1
zshrc ×1