Python while sampling

0 votes

I'm searching to make a loop to go throw samples till I reach the result. Example:

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

    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"

Now I want to stop till I have to tot>=100 . So I have to generate many "i" samples lists till I get to tot>=100.

How can I do this?

Thank you very much

Sep 10, 2018 in Python by bug_seeker
• 15,550 points

1 answer to this question.

0 votes

From guessing I would say, this could be your solution.

j, tot = 1, 1
while j<len(anytable) and tot<100 :
    tot += int( resp(i,(anytable.iloc[j,0:7].tolist())) )
    j   += 1

The condition is false if one of the inequations is false. The incementing operator += on tot is adding the integer representation of a boolean True = 1 or False = 0 to the value of tot.

answered Sep 10, 2018 by Priyaj
• 58,140 points

Related Questions In Python

+2 votes
2 answers

Error while printing hello world in python.

You must be trying this command in ...READ MORE

answered Mar 31, 2018 in Python by GandalfDwhite
• 1,320 points
0 votes
2 answers

Do-while loop in Python

A more pythonic way would be this: ``` while ...READ MORE

answered Jul 6, 2020 in Python by Composer3
0 votes
1 answer

Empty while loop in Python

while file.readline().startswith("#"):     pass The pass statement does nothing. It ...READ MORE

answered Dec 5, 2018 in Python by SDeb
• 13,300 points
0 votes
2 answers

Python UnboundLocalError error while executing script

Inside your function when you say word=word+1, ...READ MORE

answered May 22, 2020 in Python by Ibrahim Nezar
• 140 points
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,479 views
0 votes
1 answer
0 votes
1 answer

Python while sampling

I would say, this could be your ...READ MORE

answered Sep 20, 2018 in Python by Priyaj
• 58,140 points
0 votes
1 answer

Why there is no do while loop in python

There is no do...while loop because there ...READ MORE

answered Aug 6, 2018 in Python by Priyaj
• 58,140 points