What is the best way of getting random numbers in NumPy?

后端 未结 4 1514
梦谈多话
梦谈多话 2020-12-29 23:01

I want to generate random numbers in the range -1, 1 and want each one to have equal probability of being generated. I.e. I don\'t want the extremes to be less

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 23:40

    From the documentation for numpy.random.random_sample:

    Results are from the “continuous uniform” distribution over the stated interval. To sample Unif[A, b), b > a multiply the output of random_sample by (b-a) and add a:

     (b - a) * random_sample() + a
    

    Per Sven Marnach's answer, the documentation probably needs updating to reference numpy.random.uniform.

提交回复
热议问题