This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / sparse / csgraph / _tools / csgraph_from_masked

cython_function_or_method

scipy.sparse.csgraph._tools:csgraph_from_masked

Signature

def csgraph_from_masked(graph)

Summary

Construct a CSR-format graph from a masked array.

Extended Summary

Parameters

graph : MaskedArray

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

Returns

csgraph : csr_array

Compressed sparse representation of graph,

Examples

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 array of dtype 'float64'
	with 4 stored elements and shape (4, 4)>

Aliases

  • scipy.sparse.csgraph.csgraph_from_masked