Closed levrone1987 closed 2 years ago
The function from_edge_list
returns a Bunch
object with the attribute names
giving the original name of each node indexed from 0 to n-1
where n
is the number of nodes (except if no reindexing was necessary).
Here is an example for your problem:
from sknetwork.data import from_edge_list
graph = from_edge_list([('barbara', 'albert', 2), ['albert', 'edith', 1]], weighted=True, reindex=True, matrix_only=False)
adjacency = graph.adjacency
names = graph.names
print(names)
Output:
['albert' 'barbara' 'edith']
from sknetwork.embedding import Spectral
spectral = Spectral(1)
pos = spectral.fit_transform(adjacency)
name_id = {name: i for i, name in enumerate(names)}
pos[name_id['edith']]
Output:
array([1.])
Description
I am trying to form a weighted graph from a weighted edge list. Given that my nodes have specific names, I wonder how I may figure out the mapping between the actual node names and the indices.
This is the code I use for graph formation:
The idea is to calculate node embeddings with the Spectral approach:
In the above,
pos
will not be a dict which I may query by the actual node name, but a list of coordinates. How could I access the position of a node with its original name?