[英]What is the equivalent of coo_matrix in Matlab?
我正在嘗試編寫從 Python 到 Matlab 的以下代碼行。 V、Id 和 J 的大小為 (6400),在 Matlab 中為 1*6400。 pts.size 是 242。我嘗試在 Matlab 中使用“稀疏”,但沒有奏效。
A = coo_matrix((V, (Id, J)), shape=(pts.size, pts.size)).tocsr()
A = A.tobsr(blocksize=(2, 2))
對於我使用的第一行代碼:
A = sparse(V,Id,J,242,242);
我收到錯誤“在矩陣中使用稀疏索引的錯誤必須是 integer。”
MATLAB稀疏function 有幾個 forms:
S = sparse(A)
S = sparse(m,n)
S = sparse(i,j,v)
S = sparse(i,j,v,m,n)
S = sparse(i,j,v,m,n,nz)
您最有可能尋找的形式是第四種形式: S = sparse(i,j,v,m,n)
,並且希望將其(使用您的用例)稱為:
A = sparse(Id, J, V, 242, 242);
我認為您的錯誤是 MATLAB 首先需要 I 和 J 索引,然后是值,並且您將值作為第一個參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.