我正在寻找一个循环来抛出样本,直到我得到结果。例:
i=(list(np.random.randint(2, size=5)),list(np.random.randint(2, size=2)),list(np.random.randint(2, size=7)),list(np.random.randint(2, size=7)),list(np.random.randint(2, size=9)),list(np.random.randint(2, size=8)),list(np.random.randint(2, size=7)))
tot=0
for j in range(0,len(anytable)):
if resp(i,(anytable.iloc[j,0:7].tolist())): #this function "resp" gives me True and False and add 1 to variable "tot"
tot=tot+1
现在我想停下来,直到我不得不tot>=100
.所以我必须生成许多"i"样本列表,直到我到达tot>=100
。
我该怎么做?
谢谢
从猜测中我会说,这可能是你的解决方案。
j, tot = 1, 1
while j<len(anytable) and tot<100 :
tot += int( resp(i,(anytable.iloc[j,0:7].tolist())) )
j += 1
如果其中一个不等式为假,则条件为假。tot
上的合并运算符+=
是将布尔True = 1
或False = 0
的整数表示形式添加到tot
的值中。