亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將多個稀疏矩陣和密集矩陣組合在一起

如何將多個稀疏矩陣和密集矩陣組合在一起

瀟湘沐 2021-11-16 14:47:03
我一直在處理一些文本數據,但很少有稀疏矩陣和密集(numpy 數組)。我只想知道如何正確組合它們。這些是數組的類型和形狀:list1 <109248x9 sparse matrix of type '<class 'numpy.int64'>'    with 152643 stored elements in Compressed Sparse Row format>list2<109248x3141 sparse matrix of type '<class 'numpy.int64'>'    with 350145 stored elements in Compressed Sparse Row format>list3.shape   ,  type(list3)(109248, 300) ,  numpy.ndarraylist4.shape   ,  type(109248, 51)  ,  numpy.ndarray我只想將所有這些組合在一起作為一個密集矩陣。我嘗試了一些 vstack 和 hstack,但無法弄清楚。任何幫助深表感謝。Output required: (109248, 3501)
查看完整描述

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>


查看完整回答
反對 回復 2021-11-16
  • 1 回答
  • 0 關注
  • 218 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號