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 20, 2018 in Python by bug_seeker
• 15,510 points
464 views

1 answer to this question.

0 votes

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 20, 2018 by Priyaj
• 58,020 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
6,402 views
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
1,399 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,300 points
3,748 views
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
1,948 views
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 4,434 views
0 votes
1 answer
0 votes
1 answer

Python while sampling

From guessing I would say, this could ...READ MORE

answered Sep 10, 2018 in Python by Priyaj
• 58,020 points
614 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
• 58,020 points
7,656 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP