>>> import numpy as np
>>> from scipy.sparse import *
>>> x1 = np.eye(3, dtype=float)
>>> x2 = csr_matrix(x1, dtype=float, shape =x1.shape)
>>> assert x2.todense().any()==x1.any() ## holds true
>>> w = np.ones((3,1))
>>> dw1 = w - x1[:,0]
>>> dw2 = w - x2[:,0]
意想不到的结局,给了我造成scipy.csr_matrix
>>> print dw1
[[ 0. 1. 1.]
[ 0. 1. 1.]
[ 0. 1. 1.]]
而
>>> print dw2
[[ 0.]
[ 1.]
[ 1.]]
我的问题是,为什么DW1和DW2有什么不同?他们应该推迟,这是一个错误?非常感谢!
'x2'是一个稀疏*矩阵*,其行为与密集矩阵非常相似, 'np.matrix(X1)'。这里'x2 [:,0]'是(3,1)矩阵。 – hpaulj