我有在python簡單的矩陣乘法的代碼(numpy的)numpy的/ Python的執行與Matlab的
import numpy as np
import time
a = np.random.random((70000,3000));
b = np.random.random((3000,100));
t1=time.time()
c = np.dot(a,b);
t2=time.time()
print 'Time passed is %2.2f seconds' %(t2-t1
它需要大約16秒來完成乘法(C = np.dot(A,B) ;)在一個核心上。但是,當我在Matab上運行相同的乘法運算時,需要大約1秒(6個內核)才能完成乘法運算。
那麼,爲什麼Matlab比矩陣乘法numpy快2.6倍呢? (每個內核的性能對我來說很重要)
更新我這次嘗試過使用Eigen的同樣的事情。它的性能比Matlab稍好。 Eigen使用與Numpy使用相同的Blas實現。所以Blas的實現並不是性能缺點的來源。
要確保安裝的numpy的使用BLAS,我np.show_config()
enter code here
blas_info:
libraries = ['blas']
library_dirs = ['/usr/lib64']
language = f77
lapack_info:
libraries = ['lapack']
library_dirs = ['/usr/lib64']
language = f77
atlas_threads_info:
NOT AVAILABLE
blas_opt_info:
libraries = ['blas']
library_dirs = ['/usr/lib64']
language = f77
define_macros = [('NO_ATLAS_INFO', 1)]
atlas_blas_threads_info:
NOT AVAILABLE
lapack_opt_info:
libraries = ['lapack', 'blas']
library_dirs = ['/usr/lib64']
language = f77
define_macros = [('NO_ATLAS_INFO', 1)]
atlas_info:
NOT AVAILABLE
lapack_mkl_info:
NOT AVAILABLE
blas_mkl_info:
NOT AVAILABLE
atlas_blas_info:
NOT AVAILABLE
mkl_info:
NOT AVAILABLE
你是如何安裝Numpy的?也許從Ubuntu軟件包? – 2012-04-03 17:52:39
blas是來自netlib的參考blas - 最慢的blas。改爲安裝atlas或mkl。 – Anycorn 2012-04-03 17:54:52
是的,我用__sudo apt-get安裝python-numpy__ – iampat 2012-04-03 17:56:13