我一直认为scipy.linalg.norm()
和numpy.linalg.norm()
是等价的(之前的scipy版本不支持axis参数,但现在已经支持了)。然而以下简单的例子却表现出显著的不同性能:这是什么原因造成的呢?
In [1]: from scipy.linalg import norm as normsp
In [2]: from numpy.linalg import norm as normnp
In [3]: import numpy as np
In [4]: a = np.random.random(size=(1000, 2000))
In [5]: %timeit normsp(a)
The slowest run took 5.69 times longer than the fastest. This could mean that an intermediate result is being cached.
100 loops, best of 3: 2.85 ms per loop
In [6]: %timeit normnp(a)
The slowest run took 6.39 times longer than the fastest. This could mean that an intermediate result is being cached.
1000 loops, best of 3: 558 µs per loop
scipy版本为0.18.1,numpy版本为1.11.1。