小编alt*_*lto的帖子

具有混合可变和不可变值的Numpy数组

我对数组操作(点,外部,添加等)的最佳/最快方式感兴趣,同时忽略数组中的某些值.我最感兴趣的是一些(可能是50%-30%)的值被忽略的情况,并且对于中等大小的数组实际上是零,可能是100,000到1,000,000个元素.我能想到许多解决方案,但似乎没有一个能够从忽略某些值的可能优势中获益.例如:

import numpy as np
A = np.ones((dim, dim)) # the array to modify
B = np.random.random_integers(0, 1, (dim, dim)) # the values to ignore are 0
C = np.array(B, dtype = np.bool)
D = np.random.random((dim, dim)) # the array which will be used to modify A

# Option 1: zero some values using multiplication.
# some initial tests show this is the fastest
A += B * D

# Option 2: use indexing
# this seems to be the …
Run Code Online (Sandbox Code Playgroud)

python numpy

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

朱莉娅,处理键盘中断

标题说明了一切.如何处理或抓住SIGINT朱莉娅?从我假设的文档中我只想InterruptException使用如下的try/catch块来捕获

try
    while true
        println("go go go")
    end
catch ex
    println("caught something")
    if isa(ex, InterruptException)
        println("it was an interrupt")
    end
end
Run Code Online (Sandbox Code Playgroud)

但是当我用程序杀死程序时,我永远不会进入catch块^C.

编辑:上面的代码按照julia REPL的预期工作,而不是在脚本中.

sigint julia

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

标签 统计

julia ×1

numpy ×1

python ×1

sigint ×1