1 import numpy as np 2 import scipy 3 import time 4 import scipy.sparse as sparse 5 6 t = [1]+[0]*4999 7 a = scipy.matrix(np.array(t*5000, dtype=float).reshape(5000, 5000)) 8 start = time.time() 9 b = np.dot(a, a) 10 print(time.time() - start) 11 12 start = time.time() 13 aa = sparse.coo_matrix(a) 14 b = np.dot(aa, aa).todense() 15 print(time.time() - start)
参考: