當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python SciPy csgraph.csgraph_from_masked用法及代碼示例

本文簡要介紹 python 語言中 scipy.sparse.csgraph.csgraph_from_masked 的用法。

用法:

scipy.sparse.csgraph.csgraph_from_masked(graph)#

從掩碼數組構造 CSR-format 圖。

參數

graph MaskedArray

輸入圖。形狀應該是(n_nodes,n_nodes)。

返回

csgraph csr_matrix

圖的壓縮稀疏表示,

例子

>>> 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)
<4x4 sparse matrix of type '<class 'numpy.float64'>'
    with 4 stored elements in Compressed Sparse Row format>

相關用法


注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.sparse.csgraph.csgraph_from_masked。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。