scipy.sparse.csgraph.

csgraph_from_dense#

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

Erstellt einen Graphen im CSR-Format aus einer dichten Matrix.

Hinzugefügt in Version 0.11.0.

Parameter:
grapharray_like

Eingabegraph. Die Form sollte (n_nodes, n_nodes) sein.

null_valuefloat oder None (optional)

Wert, der Nicht-Kanten im Graphen kennzeichnet. Standard ist Null.

infinity_nullbool

Wenn True (Standard), werden unendliche Einträge (sowohl positive als auch negative) als Nullkanten behandelt.

nan_nullbool

Wenn True (Standard), werden NaN-Einträge als Nicht-Kanten behandelt.

Rückgabe:
csgraphcsr_array

Kompakte spärliche Darstellung des Graphen,

Beispiele

>>> from scipy.sparse.csgraph import csgraph_from_dense
>>> graph = [
... [0, 1, 2, 0],
... [0, 0, 0, 1],
... [0, 0, 0, 3],
... [0, 0, 0, 0]
... ]
>>> csgraph_from_dense(graph)
<Compressed Sparse Row sparse array of dtype 'float64'
    with 4 stored elements and shape (4, 4)>