3
$\begingroup$

I am referring to the well-known Zachary's Karate Club Network.

In Python, one can do the following:

import networkx as nx

pygr = nx.karate_club_graph()
pygr.number_of_nodes(), pygr.number_of_edges()
# (34, 78)

club_labels = nx.get_node_attributes(pygr, "club")
print(club_labels)
# {0: "Mr. Hi", ..., 9: "Officer", ...}

So, in Wolfram Language, I do the following:

ClearAll[wlgr];
wlgr = ResourceData["Zachary's Karate Club Network", All]["FullGraph"];
wlgr // {VertexCount, EdgeCount} // Through
(* 34, 78 *)

So far, so good. But the nodes in wlgr do not appear to have attributes. AnnotationKeys does not suggest any such key.

Is this an omission in ResourceData, or are the node attributes available in a different way?

$\endgroup$
2
  • 1
    $\begingroup$ "In Python, one can do the following" That is not "Python", but the NetworkX library, which happens to have this data built in. NetworkX is not part of the Python standard library, and is by far not the only library for manipulating graphs in Python. $\endgroup$
    – Szabolcs
    Commented Sep 17, 2022 at 7:37
  • $\begingroup$ It seems to me that this question is not about Mathematica, but about how to obtain a dataset. I would consider this off-topic here. $\endgroup$
    – Szabolcs
    Commented Sep 17, 2022 at 7:38

1 Answer 1

4
$\begingroup$

Zachary's Karate Club Network does not have vertex labels standardly:

https://en.wikipedia.org/wiki/Zachary%27s_karate_club

If a graph has vertex labels

g=RandomGraph[{11,19},VertexLabels->Thread[Range[11]->RandomWord[11]]]

then you get them like

AnnotationValue[g,VertexLabels]

{6->vindictively,3->costing,11->possibility,5->quadrant,8->fridge,7->integument,10->transitivity,9->prescript,4->crabwise,2->grubby,1->teeming}

Although sometimes those labels are vertices themselves:

g=ExampleData[{"NetworkGraph","FlorentineFamilies"}]
VertexList[g]

{Acciaiuoli,Medici,Castellani,Peruzzi,Strozzi,Barbadori,Ridolfi,Tornabuoni,Albizzi,Salviati,Pazzi,Bischeri,Guadagni,Ginori,Lamberteschi}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.