Lack of randomness in numpy.random

Despite the fact that the input that I work with is randomly generated, when I used matplotlib to build it, I only had a few different points! I used the expression

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

to generate data, I expected something similar to the surface. In addition, I did not add any randomness to the output, as I wanted to make sure that it worked before I did it.

The outputs are also suspicious because they had to be generated using the equation

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

Any help would be appreciated.

Here are a few types of plot:

figurefigurefigure

+4
source share
2 answers

There is nothing wrong with my numpy. It would be nice if you shared your code, since there is probably an error, 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() 

enter image description here

As others have noted, the correct way to generate your numbers is:

 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 this does not affect the result.

+5
source

This distribution looks good to me. It doesn’t look like a surface because you are not generating real numbers, but integers, so these β€œbars” are formed.

0
source

Source: https://habr.com/ru/post/1489306/


All Articles