Python稀疏矩阵运算

import numpy as np
import scipy
import time
import scipy.sparse as sparse

t = [1]+[0]*4999
a = scipy.matrix(np.array(t*5000, dtype=float).reshape(5000, 5000))
start = time.time()
b = np.dot(a, a)
print(time.time() - start)

start = time.time()
aa = sparse.coo_matrix(a)
b = np.dot(aa, aa).todense()
print(time.time() - start)

 

 

参考:

[1] https://zhuanlan.zhihu.com/p/52497385

posted @ 2019-05-08 22:33  Kayden_Cheung  阅读(980)  评论(0编辑  收藏  举报
//目录