Python 当使用稀疏矩阵时,为什么np.dot和A.dot会产生不同的结果?

Python 当使用稀疏矩阵时,为什么np.dot和A.dot会产生不同的结果?,python,numpy,matrix,scipy,sparse-matrix,Python,Numpy,Matrix,Scipy,Sparse Matrix,np.dot和.dot的文档似乎几乎相同。然而,当使用scipy稀疏矩阵运行代码时,我注意到它们会产生不同的输出。我假设这两种方法都会将稀疏矩阵转换为密集阵列输出 ###A is a sparse matrix A = sp.spdiags([1,2], 0, i,i) ### b is a 2 x2 numpy array of float64 print(np.dot(A,b)) [[<2x2 sparse matrix of type '<class 'numpy.fl

np.dot和.dot的文档似乎几乎相同。然而,当使用scipy稀疏矩阵运行代码时,我注意到它们会产生不同的输出。我假设这两种方法都会将稀疏矩阵转换为密集阵列输出

###A is a sparse matrix

A = sp.spdiags([1,2], 0, i,i)

### b is a 2 x2 numpy array of float64

print(np.dot(A,b))

[[<2x2 sparse matrix of type '<class 'numpy.float64'>'
    with 2 stored elements (1 diagonals) in DIAgonal format>
  <2x2 sparse matrix of type '<class 'numpy.float64'>'
    with 2 stored elements (1 diagonals) in DIAgonal format>]
 [<2x2 sparse matrix of type '<class 'numpy.float64'>'
    with 2 stored elements (1 diagonals) in DIAgonal format>
  <2x2 sparse matrix of type '<class 'numpy.float64'>'
    with 2 stored elements (1 diagonals) in DIAgonal format>]]

print(A.dot(b))

[[ 0.10523  0.0572 ]
 [ 0.24082  0.18558]]
###A是一个稀疏矩阵
A=sp.spdiags([1,2],0,i,i)
###b是浮点64的2 x2 numpy数组
印刷品(np.dot(A,b))
[[
]
[
]]
印刷品(A点(b))
[[ 0.10523  0.0572 ]
[ 0.24082  0.18558]]

稀疏文档警告使用
np.dot
。它使用了一个简单的转换,将其转换为稠密的,
np.array(a)
,这是错误的<代码>A.A正确
A.dot…
使用稀疏版本的矩阵乘法。