Python uses NumPy Random number generation, including uniform distribution, Normal distribution, Poisson distribution, etc
Environmental construction:
1. Install Python: Visit the official Python website( https://www.python.org/ )Download the latest version of Python and follow the installation wizard to install it.
2. Install NumPy: Open the command line or terminal and execute the following command to install:
pip install numpy
Preparation work:
1. Import NumPy library:
python
import numpy as np
Dependent class library: NumPy
Example Dataset: This example does not rely on a specific dataset.
Complete code example:
python
import numpy as np
#Generate uniformly distributed random numbers
uniform_random = np.random.uniform(low=0.0, high=1.0, size=(3, 3))
print("Uniform Random:")
print(uniform_random)
#Generate Normal distribution random number
normal_random = np.random.normal(loc=0.0, scale=1.0, size=(3, 3))
print("
Normal Random:")
print(normal_random)
#Generate Poisson distribution random numbers
poisson_random = np.random.poisson(lam=1.0, size=(3, 3))
print("
Poisson Random:")
print(poisson_random)
Output results:
Uniform Random:
[[0.94025622 0.04079137 0.92320586]
[0.40899482 0.08222986 0.82379108]
[0.04199387 0.34842895 0.73900607]]
Normal Random:
[[-0.77378323 -0.2774617 0.67839816]
[ 0.07330237 -0.13561491 -0.81868307]
[-0.32172272 -0.79865214 -1.39482353]]
Poisson Random:
[[0 0 3]
[0 0 0]
[3 2 1]]
Note: The above code is only an example code, and the generated random number results may vary each time it is run.