资源描述:
《Scipy-中的稀疏矩阵——Sparse-Matrix-in-Scipy.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Scipy中的稀疏矩阵——SparseMatrixinScipy SparseMatrixTypesBlockSparseRowmatrixclassscipy.sparse.bsr_matrix(arg1,shape=None,dtype=None,copy=False,blocksize=None)TheBlockCompressedRow(BSR)formatisverysimilartotheCompressedSparseRow(CSR)format.BSRisappropriateforspar
2、sematriceswithdensesubmatriceslikethelastexamplebelow.Blockmatricesoftenariseinvector-valuedfiniteelementdiscretizations.Insuchcases,BSRisconsiderablymoreefficientthanCSRandCSCformanysparsearithmeticoperations.AsparsematrixinCOOrdinateformatclassscipy.spar
3、se.coo_matrix(arg1,shape=None,dtype=None,copy=False)Alsoknownasthe‘ijv’or‘triplet’format.AdvantagesoftheCOOformat•facilitatesfastconversionamongsparseformats•permitsduplicateentries(seeexample)•veryfastconversiontoandfromCSR/CSCformatsDisadvantagesoftheCOO
4、format•doesnotdirectlysupport:–arithmeticoperations–slicingIntendedUsage•COOisafastformatforconstructingsparsematrices•Onceamatrixhasbeenconstructed,converttoCSRorCSCformatforfastarithmeticandmatrixvectoroperations•BydefaultwhenconvertingtoCSRorCSCformat,d
5、uplicate(i,j)entrieswillbesummedtogether.Thisfacilitatesefficientconstructionoffiniteelementmatricesandthelike.(seeexample)CompressedSparseColumnmatrixclassscipy.sparse.csc_matrix(arg1,shape=None,dtype=None,copy=False)AdvantagesoftheCSCformat•efficientarit
6、hmeticoperationsCSC+CSC,CSC*CSC,etc.•efficientcolumnslicing•fastmatrixvectorproducts(CSR,BSRmaybefaster)DisadvantagesoftheCSCformat•slowrowslicingoperations(considerCSR)•changestothesparsitystructureareexpensive(considerLILorDOK)CompressedSparseRowmatrixcl
7、assscipy.sparse.csr_matrix(arg1,shape=None,dtype=None,copy=False)AdvantagesoftheCSRformat•efficientarithmeticoperationsCSR+CSR,CSR*CSR,etc.•efficientrowslicing•fastmatrixvectorproductsDisadvantagesoftheCSRformat•slowcolumnslicingoperations(considerCSC)•cha
8、ngestothesparsitystructureareexpensive(considerLILorDOK)SparsematrixwithDIAgonalstorageclassscipy.sparse.dia_matrix(arg1,shape=None,dtype=None,copy=False)DictionaryOfkeysbasedsparsematrixclassscipy.sparse.dok