gpt4 book ai didi

ipython notebook比python : why?慢11倍

转载 作者:行者123 更新时间:2023-12-04 04:25:17 25 4
gpt4 key购买 nike

我在ipython Notebook(带有Chrome)中运行脚本,并注意到它比使用spyder作为IDE在Python中运行相同脚本的速度慢11倍。
该脚本非常简单:它只是 Pandas 数据帧上的一组循环和计算。没有输出打印到屏幕上,也没有写入外部文件。我预计代码会变慢,因为它不是矢量化的,我很欣赏Ipython可能会涉及一些开销,但是11倍……!您能想到任何原因吗?有什么建议么?

谢谢!

最佳答案

我在机器上进行了测试,发现ipython实际上更快。

$ cat ex.py 
import time
import numpy as np
now = time.time() #(seconds)
a = []
for j in range(2):
for s in range(10):
a.append(np.random.random())
then = now
print(time.time() - then)

$ python ex.py
0.142902851105

In [1]: %run ex.py
0.06136202812194824

我敢打赌,这是ipython设置中的Chrome部分,这会导致速度下降。

关于ipython notebook比python : why?慢11倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30380484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com