1 回答

TA贡献1793条经验 获得超6个赞
sparse.hstack可以连接稀疏和密集数组。它首先转换一切coo格式矩阵,创建一个新的复合data,row和col阵列,并返回一个coo矩阵(它任选地转换成另一种指定的格式):
In [379]: M=sparse.random(10,10,.2,'csr')
In [380]: M
Out[380]:
<10x10 sparse matrix of type '<class 'numpy.float64'>'
with 20 stored elements in Compressed Sparse Row format>
In [381]: A=np.ones((10,2),float)
In [382]: sparse.hstack([M,A])
Out[382]:
<10x12 sparse matrix of type '<class 'numpy.float64'>'
with 40 stored elements in COOrdinate format>
添加回答
举报