scipy.sparse.csgraph.

csgraph_masked_from_dense#

scipy.sparse.csgraph.csgraph_masked_from_dense(graph, null_value=0, nan_null=True, infinity_null=True, copy=True)#

從密集矩陣建構遮罩陣列圖形表示。

於版本 0.11.0 新增。

參數:
grapharray_like

輸入圖形。形狀應為 (n_nodes, n_nodes)。

null_valuefloat 或 None (選用)

表示圖形中非邊緣的值。預設值為零。

infinity_nullbool

若為 True (預設),則無限大的條目 (正數和負數) 會被視為空邊緣。

nan_nullbool

若為 True (預設),則 NaN 條目會被視為非邊緣

回傳:
csgraphMaskedArray

圖形的遮罩陣列表示

範例

>>> from scipy.sparse.csgraph import csgraph_masked_from_dense
>>> graph = [
... [0, 1, 2, 0],
... [0, 0, 0, 1],
... [0, 0, 0, 3],
... [0, 0, 0, 0]
... ]
>>> csgraph_masked_from_dense(graph)
masked_array(
  data=[[--,  1,  2, --],
        [--, --, --,  1],
        [--, --, --,  3],
        [--, --, --, --]],
  mask=[[ True, False, False,  True],
        [ True,  True,  True, False],
        [ True,  True,  True, False],
        [ True,  True,  True,  True]],
  fill_value=0)