小编Tru*_*ell的帖子

我可以在一行 bash 中嵌入命令吗?

我想运行命令:

$ cd which automator 
Run Code Online (Sandbox Code Playgroud)

以便将 which automator 返回的值传递给 cd。我查遍了所有内容,但找不到简单的答案。救救我吧!

unix macos bash shell

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

Numpy比纯C快吗?

我有以下C代码.在我的机器上,我在大约13秒内计时.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void) {
    clock_t begin = clock();

    double d = 0;

    for (int i = 0; i < 1e9; i++) {
        d = 1 + rand() * 5 > 10 ? 4 : rand();
    }

    clock_t end = clock();
    double time_spent = (double) (end - begin) / CLOCKS_PER_SEC;

    printf("%f", time_spent);
    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

但是这个numpy操作,我只需要几分之一秒!

a = np.random.randn(1000, 1000)
b = np.random.randn(1000, 1000)
c = a.dot(b)
Run Code Online (Sandbox Code Playgroud)

这是如何可能的,因为他们正在做相同数量(1e9操作)的工作?numpy并行化?

c python performance time numpy

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

标签 统计

bash ×1

c ×1

macos ×1

numpy ×1

performance ×1

python ×1

shell ×1

time ×1

unix ×1