The numpy.random.uniform
function allows the first and/or second parameters to be an array, not just a number. They work exactly as you were expecting:
h_max=np.random.uniform(0,20,2000)
h_min=np.random.uniform(0,h_max,2000)
However, numpy.random.*
functions, such as numpy.random.uniform
, have become legacy functions as of NumPy 1.17, and their algorithms are expected to remain as they are for backward compatibility reasons. That version didn't deprecate any numpy.random.*
functions, however, so they are still available for the time being. See also this question.
In newer applications you should make use of the new system introduced in version 1.17, including numpy.random.Generator
, if you have that version or later. One advantage of the new system is that the application relies less on global state. Generator
also has a uniform
method that works in much the same way as the legacy function numpy.random.uniform
. The following example uses Generator
and works in your case:
gen=np.random.default_rng() # Creates a default Generator
h_max=gen.uniform(0,20,2000)
h_min=gen.uniform(0,h_max,2000)