Generate random array of floats between a range

前端 未结 8 1738
孤独总比滥情好
孤独总比滥情好 2020-12-02 15:04

I haven\'t been able to find a function to generate an array of random floats of a given length between a certain range.

I\'ve looked at Random sampling but no funct

相关标签:
8条回答
  • 2020-12-02 15:53

    np.random.uniform fits your use case:

    sampl = np.random.uniform(low=0.5, high=13.3, size=(50,))
    

    Update Oct 2019:

    While the syntax is still supported, it looks like the API changed with NumPy 1.17 to support greater control over the random number generator. Going forward the API has changed and you should look at https://docs.scipy.org/doc/numpy/reference/random/generated/numpy.random.Generator.uniform.html

    The enhancement proposal is here: https://numpy.org/neps/nep-0019-rng-policy.html

    0 讨论(0)
  • 2020-12-02 15:54

    np.random.random_sample(size) will generate random floats in the half-open interval [0.0, 1.0).

    0 讨论(0)
提交回复
热议问题