-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Organising information: graphs", exercise 2 #32
Comments
|
|
@essepuntato is there a way to print only the attributes without the node identifiers? |
from networkx import DiGraph #actors nodes #movies nodes #edges print(actor_movie.nodes()) |
|
['Brad Pitt', 'Eva Green', 'George Clooney', 'Catherine Zeta-Jones', 'Johnny Depp', 'Helena Bonham Carter', "Ocean's Twelve", 'Fight Club', 'Dark Shadows'] |
|
|
from networkx import MultiDiGraph movie_stars.add_edge(1,"a") print(movie_stars.nodes(data=True)) [('a', {'weight': "Ocean's Twelve"}), ('b', {'weight': 'Fight Club'}), ('c', {'weight': 'Dark Shadows'}), (1, {'weight': 'Brad Pitt'}), (2, {'weight': 'George Clooney'}), (3, {'weight': 'Eva Green'}), (4, {'weight': 'Catherine Zeta-Jones'}), (6, {'weight': 'Helena Bonham Carter'}), (5, {})] |
|
from networkx import MultiDiGraph #create a new graph #create nodes for movies #create nodes for actors #create edges between actors and movies print(cast_graph.nodes()) |
Hi @andreamust
Not to my knowledge – of course, you can implement a function that does exactly that, if you want. Another comment for @bluebell94: use appropriate attribute names for specifying values – e.g. I do not expect to have a name associated to the attribute weight, bur rather a number. If you want to specify the names as attributes, please look at the way @andreamust did. |
Create a directed graph which relates the actors Brad Pitt, Eva Green, George Clooney, Catherine Zeta-Jones, Johnny Depp, and Helena Bonham Carter to the following movies: Ocean's Twelve, Fight Club, Dark Shadows.
The text was updated successfully, but these errors were encountered: