Module: nsl.tools.graph_utils
bookmark_borderbookmark
Stay organized with collections
Save and categorize content based on your preferences.
Utility functions for manipulating (weighted) graphs.
The functions in this module assume that weighted graphs are represented by
nested dictionaries, where the outer dictionary maps each edge source ID to
an inner dictionary that maps each edge target ID to that edge's weight. So
for example, the graph containing the edges:
A -- 0.5 --> B
A -- 0.9 --> C
B -- 0.4 --> A
B -- 1.0 --> C
C -- 0.8 --> D
would be represented by the dictionary:
{ "A": { "B": 0.5, "C": 0.9 },
"B": { "A": 0.4, "C": 1.0 },
"C": { "D": 0.8 }
}
In the documention, we say a graph is represented by a dict
:
source_id -> (target_id -> weight).
Functions
add_edge(...)
: Adds an edge to a given graph.
add_undirected_edges(...)
: Makes all edges of the given graph
bi-directional.
read_tsv_graph(...)
: Reads the file filename
containing graph edges in TSV format.
write_tsv_graph(...)
: Writes the given graph
to the file filename
in TSV format.
Other Members |
absolute_import
|
Instance of __future__._Feature
|
division
|
Instance of __future__._Feature
|
print_function
|
Instance of __future__._Feature
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-08-12 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-08-12 UTC."],[],[]]