NetworkX包中似乎没有现成的对图洗牌的函数
写一个。依赖于我实现的完全洗牌包
对图的洗牌就是改变图数据结构中节点的顺序,节点间的边关系不变
>>> from networkx.classes.graph import Graph
>>> G = Graph({0: {1: {}}, 1: {0: {}, 2: {}}, 2: {1: {}, 3: {}}, 3: {2: {}, 4: {}}, 4: {3: {}}})
>>> shuffle_graph(G, 1).adj
AdjacencyView({2: {1: {}, 3: {}}, 1: {2: {}, 0: {}}, 3: {2: {}, 4: {}}, 0: {1: {}}, 4: {3: {}}})
这样的
已经发布到了PyPI上,可以很方便的安装分发了
pip install shuffle-graph
程序里引用:
from shuffle_graph_package import *
网友评论