numpy随机码中的值错误

时间:2015-11-15 06:09:38

标签: python numpy

我尝试制作一个代码,该代码可以在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()

当我尝试运行它时,我得到了这个价值误差。有什么不对,我该怎么做才能解决它?

1 个答案:

答案 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)