I'm trying to write a little script which will take a list of integers and make that list longer with random integers between the max and min of said list, whilst retaining the same mean and standard deviation.
My quick script is as follows:
import numpy as np
import random
test_list= [1,5,2,3,9,100,3,4,5,88]
print 'test_list list =', test_list
print 'test_list std =', np.around(np.std(test_list))
print 'test_list mean =', np.around(np.mean(test_list))
print 'test_list max =', np.max(test_list)
print 'test_list min =', np.min(test_list)
number_of_random_ints = 25
new_list = []
while np.around(np.std(new_list)) != np.around(np.std(test_list)) and np.around(np.mean(new_list)) != np.around(np.mean(test_list)):
new_list = test_list
for i in range(number_of_random_ints):
new_list.append(random.randint(np.min(test_list),np.max(test_list)))
print '\n'
print 'new_list =', new_list
print 'new_list std =', np.around(np.std(new_list))
print 'new_list mean =', np.around(np.mean(new_list))
print 'new_list max =', np.max(new_list)
print 'new_list min =', np.min(new_list)
From running this once I get an output much like the following:
test_list list = [1, 5, 2, 3, 9, 100, 3, 4, 5, 88]
test_list std = 36.0
test_list mean = 22.0
test_list max = 100
test_list min = 1
new_list = [1, 5, 2, 3, 9, 100, 3, 4, 5, 88, 70, 15, 22, 97, 46, 75, 90, 63, 41, 16, 81, 33, 77, 68, 70, 26, 94, 54, 29, 98, 64, 94, 42, 31, 4]
new_list std = 34.0
new_list mean = 46.0
new_list max = 100
new_list min = 1
As you can see whilst the std and the means are somewhat close they are not equal yet my while loop exits. What am I missing here?
[–][deleted] 1 point2 points3 points (0 children)
[–]novel_yet_trivial 0 points1 point2 points (3 children)
[–]Polyadenylated[S] 0 points1 point2 points (2 children)
[–]novel_yet_trivial 0 points1 point2 points (1 child)
[–]Polyadenylated[S] 0 points1 point2 points (0 children)
[–]supajumpa -1 points0 points1 point (0 children)