np.random.uniform (low=0.0, high=1.0, size=None)
Function: random sampling from a uniform distribution [low, high]. Note that the definition field is left closed and right open, that is, it contains low but not high
Low: sampling lower bound, float type, default value is 0; high: sampling upper bound, float type, default value is 1; size: output sample number, int or tuple type, for example, size = (m, N, K), then output MNK samples, default value is 1. Return value: ndarray type, whose shape is consistent with the description in the parameter size.
The uniform () method randomly generates the next real number, which is in the range [x, y]
Evenly distributed, left closed, right open
np.random.uniform(1.75, 1, 100000000)
#output
array([1.25930467, 1.40160844, 1.53509096, ..., 1.57271193, 1.25317863,
1.62040797])
Draw a picture to see the distribution
import matplotlib.pyplot as plt
# Generate a uniformly distributed random number
x1 = np.random.uniform(-1, 1, 100000000) # output the number of samples 100000000
# Draw a graph to see the distribution
# 1) Create a canvas
plt.figure(figuresize=(20, 8), dpi=100)
# 2) Plot the histogram
plt.hist(x1, 1000) # x represents the data to be used, bins represents the number of intervals to be divided
# 3) Display the image
plt.show()
*
*
Read More:
- Python: Panda scramble data
- can‘t multiply sequence by non-int of type ‘numpy.float64‘
- Python: RNN principle realized by numpy
- Detailed explanation of OpenCV approxpolydp() function
- [leetcode] 295. Find Median from Data Stream Python
- Tensorflow: Common Usage of tf.get_variable_scope()
- Python+ Pandas + Evaluation of Music Equipment over the years (Notes)
- [How to Fix] TypeError: Cannot cast array data from dtype(‘float64‘) to dtype(‘<U32‘)….
- python: File Processing and Input and Output
- Implementation of Kalman Filter in Python
- Pytorch ValueError: Expected more than 1 value per channel when training, got input size [1, 768
- Python: LeetCode 43 Multiply Strings
- Python+OpenCV: How to Use Background Subtraction Methods
- Mxnet.gluon Load Pre Training
- Python: How to get the size of the picture (byte/kb/mb)
- Python error: urllib.error.HTTPError : http Error 404: not found
- Python uses try… Except… To output detailed errors
- How to Fix keyerror in Python dictionary lookup
- The lenet model trained by Python failed to predict its own handwritten pictures
- Python: How to Set Line breaks and tabs for Strings