IPython 并行计算全解析
1. IPython 并行魔法命令
在 IPython 中,有许多强大的魔法命令可用于并行计算。例如, %px 命令允许在多个引擎上执行代码。当执行某些操作时,可能不会有返回值,但每个引擎都有自己的数组对象副本,我们可以对其进行操作。
In [27]: %px numpy.linalg.eigvals(arrays)
Out[0:7]: array([ 1.49907907, 0.28987838, 0.49496096])
Out[1:7]: array([ 1.43756182, 0.27747814, 0.45153931])
Out[2:7]: array([ 1.51325036+0.j, -0.06614375+0.30396195j, -0.06614375-0.30396195j])
Out[3:7]: array([ 1.71117020+0.j, -0.13081468+0.42304986j, -0.13081468-0.42304986j])
魔法命令还可以远程运行,比如启动 %pylab 魔法:
In [44]: %px %pylab inline
[stdout:0] Populating the interactive namespace from numpy and matplotlib
[stdout:1] Populating the interactive namespace from
超级会员免费看
订阅专栏 解锁全文
521

被折叠的 条评论
为什么被折叠?



