scipy.sparse.csgraph.csgraph_to_masked¶
- scipy.sparse.csgraph.csgraph_to_masked(csgraph)¶
将稀疏图形表示转换为掩码数组表示
0.11.0 新版功能.
- 参数
- csgraphcsr矩阵、csc矩阵或lil矩阵
图形的稀疏表示。
- 退货
- graphMaskedArray
稀疏图的掩码密集表示。
示例
>>> from scipy.sparse import csr_matrix >>> from scipy.sparse.csgraph import csgraph_to_masked
>>> graph = csr_matrix( [ ... [0, 1, 2, 0], ... [0, 0, 0, 1], ... [0, 0, 0, 3], ... [0, 0, 0, 0] ... ]) >>> graph <4x4 sparse matrix of type '<class 'numpy.int64'>' with 4 stored elements in Compressed Sparse Row format>
>>> csgraph_to_masked(graph) masked_array( data=[[ --, 1.0, 2.0, --], [ --, --, --, 1.0], [ --, --, --, 3.0], [ --, --, --, --]], mask=[[ True, False, False, True], [ True, True, True, False], [ True, True, True, False], [ True, True, True, True]], fill_value=1e+20)