gpt4 book ai didi

python - numpy.random 中缺乏随机性

转载 作者:太空狗 更新时间:2023-10-30 02:47:05 24 4
gpt4 key购买 nike

虽然我正在处理的输入数据是随机生成的,但当我使用 matplotlib 对其进行绘图时,我只得到了几个不同的不同点!我用了表达方式

[[numpy.random.randint(0,20) + numpy.random.random() for i in xrange(100)] for j in xrange(2)]

为了生成数据,我希望生成类似于表面的数据。此外,我没有向输出添加任何随机性,因为我想确保在我这样做之前拟合有效。

输出也很可疑,因为它们应该是用等式生成的

z = 112x/2 + 2^.15y + 109

如有任何帮助,我们将不胜感激。

以下是剧情的一些观点:

figure figure figure

最佳答案

我的 numpy 没问题。如果您共享您的代码会很好,因为可能存在错误,因为以下工作正常:

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

x, y = np.array([[np.random.randint(0,20) + np.random.random()
for i in xrange(100)] for j in xrange(2)])
z = 112*x/2 + 2**.15*y + 109

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x, y, z)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')

plt.show()

enter image description here

正如其他人指出的那样,生成数字的正确方法是:

x, y = np.random.rand(2, 100) * 20

甚至

x, y = np.random.randint(20, size=(2, 100)) + np.random.rand(2, 100)

但这对结果没有影响。

关于python - numpy.random 中缺乏随机性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17429525/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com