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

    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

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,350 points
22 views

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
• 56,900 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
114 views
0 votes
1 answer

Do-while loop in Python

Python does not have a do-while construct.  If ...READ MORE

answered May 11, 2018 in Python by Hamartia's Mask
• 1,580 points
131 views
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,180 points
302 views
0 votes
1 answer

Python UnboundLocalError error while executing script

The reason for this error is that ...READ MORE

answered Jan 22 in Python by Omkar
• 67,660 points
65 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 328 views
0 votes
1 answer

Python while sampling

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

answered Sep 20, 2018 in Python by Priyaj
• 56,900 points
32 views
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
• 56,900 points
162 views