日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言稀疏矩阵做除法,稀疏矩阵的除法

發(fā)布時(shí)間:2025/3/20 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言稀疏矩阵做除法,稀疏矩阵的除法 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

小編典典

我M閑逛:

In [241]: M

Out[241]:

<6x3 sparse matrix of type ''

with 6 stored elements in Compressed Sparse Row format>

In [242]: M.A

Out[242]:

array([[1, 0, 0],

[0, 1, 0],

[0, 0, 1],

[0, 1, 0],

[0, 0, 1],

[1, 0, 0]], dtype=uint8)

In [243]: M.sum(1) # dense matrix

Out[243]:

matrix([[1],

[1],

[1],

[1],

[1],

[1]], dtype=uint32)

In [244]: M/M.sum(1) # dense matrix - full size of M

Out[244]:

matrix([[ 1., 0., 0.],

[ 0., 1., 0.],

[ 0., 0., 1.],

[ 0., 1., 0.],

[ 0., 0., 1.],

[ 1., 0., 0.]])

這將解釋內(nèi)存錯(cuò)誤-如果內(nèi)存錯(cuò)誤M太大,則會(huì)M.A產(chǎn)生內(nèi)存錯(cuò)誤。

In [262]: S = sparse.csr_matrix(M.sum(1))

In [263]: S.shape

Out[263]: (6, 1)

In [264]: M.shape

Out[264]: (6, 3)

In [265]: M/S

....

ValueError: inconsistent shapes

我不完全確定這里發(fā)生了什么。

元素明智的乘法工作

In [266]: M.multiply(S)

Out[266]:

<6x3 sparse matrix of type ''

with 6 stored elements in Compressed Sparse Row format>

所以如果我構(gòu)造S為S = sparse.csr_matrix(1/M.sum(1))

如果某些行的總和為零,則存在除以零的問題。

如果我修改M為0行

In [283]: M.A

Out[283]:

array([[1, 0, 0],

[0, 1, 0],

[0, 0, 0],

[0, 1, 0],

[0, 0, 1],

[1, 0, 0]], dtype=uint8)

In [284]: S = sparse.csr_matrix(1/M.sum(1))

/usr/local/bin/ipython3:1: RuntimeWarning: divide by zero encountered in true_divide

#!/usr/bin/python3

In [285]: S.A

Out[285]:

array([[ 1.],

[ 1.],

[ inf],

[ 1.],

[ 1.],

[ 1.]])

In [286]: M.multiply(S)

Out[286]:

<6x3 sparse matrix of type ''

with 5 stored elements in Compressed Sparse Row format>

In [287]: _.A

Out[287]:

array([[ 1., 0., 0.],

[ 0., 1., 0.],

[ 0., 0., 0.],

[ 0., 1., 0.],

[ 0., 0., 1.],

[ 1., 0., 0.]])

這不是最好M的證明,但是它建議一種有用的方法。行總和將是密集的,因此您可以使用通常的密集數(shù)組方法清除其逆。

2020-12-20

總結(jié)

以上是生活随笔為你收集整理的c语言稀疏矩阵做除法,稀疏矩阵的除法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。