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)#

Construct a masked array graph representation from a dense matrix.

Added in version 0.11.0.

Parameters:
grapharray_like

Input graph. Shape should be (n_nodes, n_nodes).

null_valuefloat or None, optional

Value that denotes non-edges in the graph. Default is zero.

nan_nullbool, optional

If True (default), then NaN entries are treated as non-edges

infinity_nullbool, optional

If True (default), then infinite entries (both positive and negative) are treated as null edges.

copybool, optional

If True (default), then the array data is copied. See numpy.array for more details.

Returns:
csgraphMaskedArray

masked array representation of graph

Examples

>>> 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)