我正在使用csr_matrix((data, indices, indptr), shape=[row, col])方法创建一个csr矩阵。执行构造方法csr_matrix()比构建data, indices, indptr本身花费了4倍多的时间。既然我已经有了(data, indices, indptr)元组,那么构造一个csr矩阵难道不是很琐碎(而且快速)吗?
我的代码和时间统计如下:
data = ... # 2.207s
indices = ... # 11.065s
indptr = ... # 0.047s
matrix = csr_matrix((data, indices, indptr), shape=(row, col)) # 57.806s发布于 2015-07-09 20:20:39
您传递的数组似乎很大,因此它们可能在某个地方被复制,由此产生的内存问题导致了速度的放缓。
有几种方法可以复制数组。如果这些条件中的任何一个都是假的,则将产生副本:
indices和indptr需要具有适当的索引dtype。numpy.ndarray)。copy kwarg必须是False。默认情况下,这是错误的,因此这不太可能是问题所在。https://stackoverflow.com/questions/31322599
复制相似问题