为什么我得到的图形形状与我的导师的不同?

2024-09-27 07:31:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着画的东西:

G = nx.gnp_random_graph(20,0.5)

我得到了什么节目(G) :

my result

我的导师画了什么:用同样的命令:

instructor's result


Tags: 命令myrandomresult节目graphnx导师
1条回答
网友
1楼 · 发布于 2024-09-27 07:31:50

代码如下:

G = nx.gnp_random_graph(20,0.5)
G = nx.gnp_random_graph(n=20, p=0.5, seed=None, directed=False)  # equivalent

将使用当前时间或其他资源初始化PRNG(如seed=None

由于networkx是纯python和reuses the standardlib,因此可以归结为python's random module seed

random.seed(a=None, version=2)

Initialize the random number generator.

If a is omitted or None, the current system time is used. If randomness sources are provided by the operating system, they are used instead of the system time (see the os.urandom() function for details on availability).

If a is an int, it is used directly.

With version 2 (the default), a str, bytes, or bytearray object gets converted to an int and all of its bits are used.

With version 1 (provided for reproducing random sequences from older versions of Python), the algorithm for str and bytes generates a narrower range of seeds.

Changed in version 3.2: Moved to the version 2 scheme which uses all of the bits in a string seed.

您可以设置种子,使其具有确定性,如:

G = nx.gnp_random_graph(20,0.5,0)  # or any other int

最后一行总是输出相同的图形(文档显式地调用int!)。你知道吗

如果你的导师没有修复种子,那么试图复制它就有点假了。你知道吗

相关问题 更多 >

    热门问题