小编bou*_*gui的帖子

循环背景工作

我尝试在bash中的for循环中运行后台作业:

for i in $(seq 3); do echo $i ; sleep 2 & ; done
Run Code Online (Sandbox Code Playgroud)

我收到错误:

bash: syntax error near unexpected token `;'
Run Code Online (Sandbox Code Playgroud)

在zsh中命令行有效.

bash

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

python中的测地距离变换

在python distance_transform_edt中,scipy.ndimage.morphology模块中有函数.我将它应用于一个简单的情况,以计算掩盖的numpy数组中单个单元格的距离.

但是,该函数删除数组的掩码,并按预期计算每个单元格的欧几里德距离,其中非空值来自参考单元格,具有空值.

以下是我在博文中给出的一个例子:

%pylab
from scipy.ndimage.morphology import distance_transform_edt
l = 100
x, y = np.indices((l, l))
center1 = (50, 20)
center2 = (28, 24)
center3 = (30, 50)
center4 = (60,48)
radius1, radius2, radius3, radius4 = 15, 12, 19, 12
circle1 = (x - center1[0])**2 + (y - center1[1])**2 < radius1**2
circle2 = (x - center2[0])**2 + (y - center2[1])**2 < radius2**2
circle3 = (x - center3[0])**2 + (y - center3[1])**2 < radius3**2
circle4 …
Run Code Online (Sandbox Code Playgroud)

python arrays numpy distance scipy

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

为外部显示添加udev规则

我写了一个小的shell脚本,用xrandr配置连接的外部显示器.

# cat /home/didi/bin/monitor_autoswitcher.sh 
#!/bin/bash

xrandr | grep "HDMI1 connected"
if [[ $? == 0 ]]; then
  # is connected
  xrandr --output HDMI1 --right-of LVDS1 --auto
else
  # not connected
  xrandr --output HDMI1 --auto
fi

xrandr | grep "VGA1 connected"
if [[ $? == 0 ]]; then
  # is connected
  xrandr --output VGA1 --right-of LVDS1 --auto
else
  # not connected
  xrandr --output VGA1 --auto
fi
Run Code Online (Sandbox Code Playgroud)

这样可行.现在我想让它自动触发,并发现这可以用udev完成.我试过了

udevadm monitor
Run Code Online (Sandbox Code Playgroud)

当插入外部显示输出时

KERNEL[465828.240250] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
UDEV  [465828.243549] change   /devices/pci0000:00/0000:00:02.0/drm/card0 (drm)
Run Code Online (Sandbox Code Playgroud)

插上电源时

KERNEL[465836.844209] …
Run Code Online (Sandbox Code Playgroud)

linux xrandr udev

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

计算网格上两点之间恰好有 n 个节点的最短路径

我在网格上定义了以下 3D 表面:

%pylab inline
def muller_potential(x, y, use_numpy=False):
    """Muller potential
    Parameters
    ----------
    x : {float, np.ndarray, or theano symbolic variable}
    X coordinate. If you supply an array, x and y need to be the same shape,
    and the potential will be calculated at each (x,y pair)
    y : {float, np.ndarray, or theano symbolic variable}
    Y coordinate. If you supply an array, x and y need to be the same shape,
    and the potential will be calculated at each (x,y …
Run Code Online (Sandbox Code Playgroud)

python numpy shortest-path

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

scipy.spatial.distance.squareform的反函数

是否有scipy.spatial.distance.squareform的反函数?如果没有,编写它来处理巨大距离矩阵的最佳方法是什么?

python scipy

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

标签 统计

python ×3

numpy ×2

scipy ×2

arrays ×1

bash ×1

distance ×1

linux ×1

shortest-path ×1

udev ×1

xrandr ×1