dhart.spatialstructures.Graph.get_node_attributes

Graph.get_node_attributes(attribute: str) List[str]

Get scores of every node for a specific attribute

Parameters:

attribute – The unique key of the attribute to get scores for

Returns:

A list of strings representing the score of every node in the graph for attribute in order of ID. If attribute does not exist in the graph, then None is returned. For nodes that have never been assigned a score for a specific attribute, the score at the index of their ID will be None.

Example

Create a graph, add some nodes, assign some attributes to its nodes then read them from the 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)
>>> # Get attribute scores from the graph
>>> g.get_node_attributes(attr)
['zero', 'one', 'two']