我想在 python 中从两个不同的范围 [0, 0.3) 和 [0.7, 1) 生成随机数。
numpy.random.uniform
可以选择仅从一个特定间隔生成。
这个怎么样?
first_interval = np.array([0, 0.3])
second_interval = np.array([0.7, 1])
total_length = np.ptp(first_interval)+np.ptp(second_interval)
n = 100
numbers = np.random.random(n)*total_length
numbers += first_interval.min()
numbers[numbers > first_interval.max()] += second_interval.min()-first_interval.max()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句