Numpy np.dot运行时间很长

Numpy np.dot运行时间很长,numpy,Numpy,我正在用numpy实现一个矩阵分解算法,发现我的代码运行了很长时间,导致jupyter内核重新启动。我将错误定位到使用np.dot的一行代码中。下面是一段代码,其中的行运行缓慢: H = np.random.rand(n_features, 8) print(H_start.T.shape) #(8, 10285) print(t2t_matrix.shape) #(10285, 10285) S_nom = H_start.T.dot(t2t_matrix) # this line takes

我正在用numpy实现一个矩阵分解算法,发现我的代码运行了很长时间,导致jupyter内核重新启动。我将错误定位到使用np.dot的一行代码中。下面是一段代码,其中的行运行缓慢:

H = np.random.rand(n_features, 8)
print(H_start.T.shape) #(8, 10285)
print(t2t_matrix.shape) #(10285, 10285)
S_nom = H_start.T.dot(t2t_matrix) # this line takes a long time

有什么想法吗?我想不到(1028510285)矩阵会花这么长时间?

事实证明t2t_矩阵是一个“scipy.sparse.csc.csc_矩阵”,并且
H_start是一个“numpy.ndarray”。我必须使用t2t_矩阵转换t2t_矩阵。toarray()。如果没有转换,jupyter笔记本会崩溃。

您打印了
H\u start
形状,但在点中使用了
H
。什么是“很长时间”?很长时间=超过一个小时,然后jupyter笔记本会崩溃。请看我下面的答案-它实际上是使用不同的矩阵类型执行点积。当我们不知道t2t_矩阵是如何生成的时,这不是一个非常有用的示例。任何人都不可能通过提供的代码发现数据类型的差异。是的,
dense.dot(sparse)
无法正常工作<代码>稀疏。点(密集)很好,就像
稀疏*稀疏
一样。但是纯稠密
尝试从稀疏到稠密的简单转换,这是错误的。比较
np.array(t2t\u矩阵)
t2t\u矩阵toarray()