Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import argparse
- from random import randint
- parser = argparse.ArgumentParser(description="Hello, please give the array of population iteams and the \
- number of items to be chosen")
- parser.add_argument('-l', '--list', help='Comma separated delimited list input', type=str)
- parser.add_argument('number', help='The number of items to be chosen')
- args = parser.parse_args()
- population = [int(item) for item in args.list.split(',')]
- print(population)
- m = args.number
- def SelectionSampling(population, m):
- m = int(m) #Is there a better way to right this?
- S = []
- k, t = 0, 0
- n = len(population)
- while k < m:
- u = randint(0, 1)
- if u * (n - t) < (m - k):
- S.append(population[t]) # List index out of range
- k += 1
- t += 1
- return S
- sample = SelectionSampling(population, m)
- print(sample)
Advertisement
Add Comment
Please, Sign In to add comment