Sau*_*tro 10
是的,您可以使用scipy.sparse.vstack和scipy.sparse.hstack使用numpy.vstack和numpy.hstack使用密集阵列相同的方式.
例:
from scipy.sparse import coo_matrix
m = coo_matrix(np.array([[0,0,1],[1,0,0],[1,0,0]]))
a = np.ones(m.shape)
Run Code Online (Sandbox Code Playgroud)
用np.vstack:
np.vstack((a,m))
#ValueError: all the input array dimensions except for the concatenation axis must match exactly
Run Code Online (Sandbox Code Playgroud)
用scipy.sparse.vstack:
scipy.sparse.vstack((a,m))
#<6x3 sparse matrix of type '<type 'numpy.float64'>'
# with 12 stored elements in COOrdinate format>
Run Code Online (Sandbox Code Playgroud)