我尝试制作一个代码,该代码可以在0到1的间隔内获得0.5到0.6之间的数字。
from numpy import *
import sys
N = int(sys.argv[1])
r = random.uniform(0, 1, N)
M = sum(0.5 <= r, r <= 0.6)
p= float(M)/N
print p
M = sum(0.5 <= r >= 0.6)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
当我尝试运行它时,我得到了这个价值误差。有什么不对,我该怎么做才能解决它?
答案 0 :(得分:-2)
import system.*
N = int(system.args[1])
r = random.uniform(0, 1, N)
M = sum(0.5 <= r, r <= 0.6)
p= float(M)/N
print p
M = sum(0.5 <= r >= 0.6)