1 np.random.randint
"randint" is the abbreviation of "random integer", which means generating a random integer.
np.random.randint
is a function in the NumPy library that generates random integers. The following is the general syntax of the function:
np.random.randint(low, high, size)
in:
low
is the lower bound (inclusive) of the generated random integers.high
is the upper limit of the generated random integers (excluding , i.e. the range of generated integers is[low, high)
).size
is the shape of the generated array.
This function generates an array of random integers with the specified shape. You can use the generated random integers for various applications such as simulating data, random sampling, and more.
x2 = np.random.randint(0, 300, size=(300, 1))
two np.random.randn
randn" stands for "random normal", meaning that the random numbers generated are from the normal distribution (also known as). Normal distribution
np.random.randn(300, 1)
is an operation that uses the NumPy library to generate random numbers. This generates an array of shape (300, 1) whose elements are drawn from the standard normal distribution (mean 0 and standard deviation 1 ) randomly selected values.
Three np.linspace
np.linspace
is a function in the NumPy (Numerical Python) library that is used to create equally spaced numerical sequences. It returns evenly spaced numbers generated within the range specified by . This function is typically used to generate a one-dimensional array containing a series of values evenly distributed within a specified range.
np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
With the following parameters:
start
: The starting value of the sequence.stop
: The end value of the sequence.num
: Number of elements in the sequence, default is 50.endpoint
: If True (the default), the sequence includesstop
values; if False, the sequence does not includestop
values.retstep
: If True, the return value will be a tuple containing the sequence and step size.dtype
: Returns the data type of the array.
import numpy as np
# 创建一个包含10个均匀分布的数值的数组,范围从1到5
arr = np.linspace(1, 5, 5)
print(arr) # [1. 2. 3. 4. 5.]