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>
添加回答
舉報