[英]NetworkX: list of directed edges in a triad census
In NetworkX, I can use the nx.triadic_census(g)
to give me a list of triads in my network.在 NetworkX 中,我可以使用nx.triadic_census(g)
为我提供网络中的黑社会列表。
Out:
{'003': 1434217,
'012': 282025,
'102': 32640,
'021D': 21,
'021U': 267246,
'021C': 445}
I wanted to know how I can list the directed edges belonging to a triad.我想知道如何列出属于三元组的有向边。 For example, in Pyspark, to list the nodes/edges in triad "102" : g.find("(a)-[e]->(b); (b)-[e2]->(a)").show()
例如,在 Pyspark 中,要列出三元组 "102" 中的节点/边: g.find("(a)-[e]->(b); (b)-[e2]->(a)").show()
and it will give you它会给你
| a| e| b| e2|
+--------------------+-------------+--------------------+--------------+
|[US, United State...| [US, AZ, 0]| [AZ, Azerbaijan]| [AZ, US, 637]|
| [LU, Luxembourg]|[LU, BE, 213]| [BE, Belgium]|[BE, LU, 1470]|
| [FI, Finland]| [FI, CZ, 24]|[CZ, Czech Republic]| [CZ, FI, 51]|
| [HU, Hungary]| [HU, PL, 0]| [PL, Poland]| [PL, HU, 231]|
|[RU, Russian Fede...| [RU, UA, 0]| [UA, Ukraine]| [UA, RU, 0]|
Is there a way for me to do this in NetworkX?有没有办法让我在 NetworkX 中做到这一点?
There is no function in networkx
that allow you to do it, so you should implement it manually. networkx
中没有允许您执行此操作的功能,因此您应该手动实现它。 I modified the networkx.algorithms.triads
code to return triad nodes, not their count.我修改了networkx.algorithms.triads
代码以返回三元组节点,而不是它们的计数。 You can find it here .你可以在这里找到它。 It can be modified with replacing tuple in census['...'].add(tuple(sorted([u, v, w])))
lines to add edges instead of nodes.可以通过在census['...'].add(tuple(sorted([u, v, w])))
行中替换元组来修改它以添加边而不是节点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.