is_negatively_weighted#
- is_negatively_weighted(G, edge=None, weight='weight')[源代码]#
返回true
G
边缘负权重。- 参数
- G图表
网络X图。
- edge元组,可选
一个2元组,指定
G
这一点将受到考验。如果没有,则每条边G
是经过测试的。- weight: string, optional
用于查询边权重的属性名称。
- 返回
- 布尔尔
表示如果
G
或指定的边为负权重。
- 加薪
- NetworkXError
如果指定的边缘不存在。
实例
>>> G = nx.Graph() >>> G.add_edges_from([(1, 3), (2, 4), (2, 6)]) >>> G.add_edge(1, 2, weight=4) >>> nx.is_negatively_weighted(G, (1, 2)) False >>> G[2][4]["weight"] = -2 >>> nx.is_negatively_weighted(G) True >>> G = nx.DiGraph() >>> edges = [("0", "3", 3), ("0", "1", -5), ("1", "0", -2)] >>> G.add_weighted_edges_from(edges) >>> nx.is_negatively_weighted(G) True