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:
- dtype=np.int error: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`.
- Python: Np.where Ternary Operator
- [Solved] Np.argwhere error: maximum recursion depth exceeded while calling
- [Solved] module ‘numpy.random‘ has no attribute ‘default_rng‘ gensim.model
- [Solved] Python Networkx Error: Network error: random_state_index is incorrect
- Tensorflow: Common Usage of tf.get_variable_scope()
- For the problem of rejecting old usage errors after numpy is updated, modified in numpy 1.20; for more details and guidance
- [Solved] Python matplotlib Error: RuntimeError: In set_size: Could not set the fontsize…
- Plt.acorr() Function Error: ValueError: object too deep for desired array
- Solution warning: userwarning: fixedformatter should only be used together with fixedlocator (illustrated version)!)
- [Solved] matplotlib.units.ConversionError: Failed to convert value(s) to axis units: ‘LiR‘
- Python: Panda scramble data
- [Solved] error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function ‘copyMakeBorder‘
- Matplotlib draw error: Fail to allocate bitmap [How to Solve]
- Error:output with shape [1, 224, 224] doesn‘t match the broadcast shape [3, 224, 224]
- import matplotlib.pyplot as plt [How to Solve]
- [Solved] RuntimeError: scatter(): Expected dtype int64 for index
- RuntimeError: Invalid DISPLAY variable [How to Solve]
- [Solved] Runtime error: expected scalar type Float but found Double
- [Solved] AttributeError: ‘HTMLWriter‘ object has no attribute ‘_temp_names‘