I have written some code which takes a sample of 100 numbers and randomly samples them to increase the list of numbers, then cuts them back down to 100 at random.
I am counting the number of iterations through the loop it takes for all the numbers in the list to be the same number.
output = open("results.txt", 'w')
for i in range(100):
population = range(0, 100)
TTF = 0
while len(set(population)) != 1:
scalingfactor = np.random.poisson(5, 100)
sample = np.repeat(population, scalingfactor)
decrease-to-ten = np.random.choice(sample, 100)
population = decrease-to-ten
results += 1
output.write(str(results))
I am trying to output the numbers to a text file as a list, but I can't manage it.
output.write(str(results))
This gives me all the numbers together as one long string of numbers.
output.write(TTF)
gives me this error:
TypeError: expected a character buffer object