我试图比较bmat和hstack在连接巨大的坐标矩阵时的速度
我的代码:
from scipy.sparse import bmat, coo_matrix, hstack
import timeit
import numpy as np
a = np.add(*np.indices((1000,1000)))
A = coo_matrix(a)
B = coo_matrix(a)
t = timeit.timeit("hstack([A,B]).toarray()", "from __main__ import A, B, hstack", number= 2000)
print(t)
tt = timeit.timeit("bmat([[A,B]])", "from __main__ import A, B, bmat", number = 2000)
print(tt)
从我的实验来看,bmat似乎比hstack有更快的处理速度
85.89499111475607
71.0423545148451
我想知道我的测试方法是否正确,或者在coo_矩阵庞大的情况下,是否有任何东西可以让hstack表现得更好?我应该使用bmat还是hstack,从实验来看,bmat似乎更适合使用,但我想知道两者的区别
目前没有回答
相关问题 更多 >
编程相关推荐