import numpy as np
import time
xyz = np.random.rand(3,2399,2399)
t1 = time.time()
a = []
for _ in range(10):
a.append((xyz/np.linalg.norm(xyz, axis=0)-np.array([0,0,1])[:,np.newaxis,np.newaxis])/3)
t2 = time.time()
print(t2-t1)
这是我的代码。 Python 3在21.24s运行此代码,而IPython只使用12.6s。 IPython做了什么魔术?
Python 3.6.1
IPython 5.3.0