{ } Raw JSON

bundles / scipy 1.18.0 / scipy / sparse / csgraph / _tools / csgraph_to_masked

cython_function_or_method

scipy.sparse.csgraph._tools:csgraph_to_masked

Signature

def csgraph_to_masked(csgraph)

Summary

Convert a sparse graph representation to a masked array representation.

Extended Summary

Parameters

csgraph : csr_array, csc_array, or lil_array

Sparse representation of a graph.

Returns

graph : MaskedArray

The masked dense representation of the sparse graph.

Examples

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)

Aliases

  • scipy.sparse.csgraph.csgraph_to_masked