scipy.sparse.csgraph.
csgraph_from_masked#
- scipy.sparse.csgraph.csgraph_from_masked(graph)#
从掩码数组构建CSR格式的图。
Added in version 0.11.0.
- 参数:
- 图MaskedArray
输入图。形状应为 (n_nodes, n_nodes)。
- 返回:
- csgraph
csr_matrix
图的压缩稀疏表示,
- csgraph
示例
>>> import numpy as np >>> from scipy.sparse.csgraph import csgraph_from_masked
>>> graph_masked = np.ma.masked_array(data =[ ... [0, 1, 2, 0], ... [0, 0, 0, 1], ... [0, 0, 0, 3], ... [0, 0, 0, 0] ... ], ... mask=[[ True, False, False, True], ... [ True, True, True, False], ... [ True, True, True, False], ... [ True, True, True, True]], ... fill_value = 0)
>>> csgraph_from_masked(graph_masked) <Compressed Sparse Row sparse matrix of dtype 'float64' with 4 stored elements and shape (4, 4)>