dhart.spatialstructures.Graph.add_node_attributes¶
- Graph.add_node_attributes(attribute: str, ids: int | List[int], scores: str | List[Any]) None ¶
Add attributes to one or more nodes
- Parameters:
attribute – Unique key of the attribute to assign scores for
ids – Node IDS in the graph to assign attributes to
scores – Scores to assign to the ids at the same index
- Preconditions:
IDs in ids must already belong to nodes in the graph
The length of scores and ids must match
- Raises:
ValueError – the length of ids and scores did not match
Example
Add node attributes to a graph
>>> from dhart.spatialstructures import Graph >>> # Create a simple graph with 3 nodes >>> g = Graph() >>> g.AddEdgeToGraph(0, 1, 100) >>> g.AddEdgeToGraph(0, 2, 50) >>> g.AddEdgeToGraph(1, 2, 20) >>> csr = g.CompressToCSR()
>>> # Add node attributes to the simple graph >>> attr = "Test" >>> ids = [0, 1, 2] >>> scores = ["zero", "one", "two"] >>> g.add_node_attributes(attr, ids, scores)
>>> # To ensure that they've been added properly we will call >>> # get_node_attributes. >>> g.get_node_attributes(attr) ['zero', 'one', 'two']