简体   繁体   English

numpy.random缺乏随机性

[英]Lack of randomness in numpy.random

Although the input data I'm working is randomly generated, when I used matplotlib to graph it, I got only a few different distinct points! 虽然我正在使用的输入数据是随机生成的,但当我使用matplotlib绘制图形时,我只得到了几个不同的不同点! I used the expression 我用过表达式

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

to generate the data I expected something that would resemble a surface. 生成我期望的类似于表面的数据。 Also, I did not add any randomness to the output, as I wanted to ensure that the fit worked before I did. 另外,我没有在输出中添加任何随机性,因为我想确保在我之前合适。

The outputs are also suspicious, as they should have been generated with the equation 输出也是可疑的,因为它们应该是用等式生成的

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

Any help would be appreciated. 任何帮助,将不胜感激。

Here are some views of the plot: 以下是情节的一些看法:

数字数字数字

There's nothing wrong with my numpy. 我的numpy没什么不对。 It would be good if you shared your code, as the error is probably there, since the following works just fine: 如果您共享代码会很好,因为错误可能存在,因为以下工作正常:

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()

在此输入图像描述

As other have noted, the right way of generating your numbers would be: 正如其他人所指出的那样,产生数字的正确方法是:

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

or even 甚至

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

but that has no effect on the outcome. 但这对结果没有影响。

This distribution looks OK to me. 这个发布对我来说很好看。 It doesn't look like a surface because you're not generating real numbers, just integers, which is why those "bars" are being formed. 它看起来不像是一个表面因为你没有生成实数,只有整数,这就是为什么这些“条形”正在形成的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM