scipy.sparse.csgraph.
csgraph_to_masked#
- scipy.sparse.csgraph.csgraph_to_masked(csgraph)#
將稀疏圖形表示法轉換為遮罩陣列表示法
在 0.11.0 版本中新增。
- 參數:
- csgraphcsr_array、csc_array 或 lil_array
圖形的稀疏表示法。
- 回傳:
- graphMaskedArray
稀疏圖形的遮罩密集表示法。
範例
>>> from scipy.sparse import csr_array >>> from scipy.sparse.csgraph import csgraph_to_masked
>>> graph = csr_array( [ ... [0, 1, 2, 0], ... [0, 0, 0, 1], ... [0, 0, 0, 3], ... [0, 0, 0, 0] ... ]) >>> graph <Compressed Sparse Row sparse array of dtype 'int64' with 4 stored elements and shape (4, 4)>
>>> 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)