attribute_mixing_dict#

attribute_mixing_dict(G, attribute, nodes=None, normalized=False)[源码]#

返回属性的混合矩阵的字典表示。

参数
G

NetworkX 图对象。

attribute字符串

节点属性键。

nodes: 列表或可迭代对象(可选)

使用容器中的节点构建字典。默认是所有节点。

normalized布尔值(默认为 False)

如果为 False,返回计数;如果为 True,返回概率。

返回值
d字典

属性对出现的计数或联合概率。

示例

>>> G = nx.Graph()
>>> G.add_nodes_from([0, 1], color="red")
>>> G.add_nodes_from([2, 3], color="blue")
>>> G.add_edge(1, 3)
>>> d = nx.attribute_mixing_dict(G, "color")
>>> print(d["red"]["blue"])
1
>>> print(d["blue"]["red"])  # d symmetric for undirected graphs
1