I'm trying to generate a list of 8 numbers with the following for code:
import numpy as np
import pandas as pd
n2 = np.random.uniform(0.1, 1.5)
c2 = np.random.uniform(4,14)
c3 = np.random.uniform(0.1,2.9)
ic4 = np.random.uniform(0.01,1)
nc4 = np.random.uniform(0.01,1)
ic5 = np.random.uniform(0,0.2)
nc5 = np.random.uniform(0,0.01)
comp_list = []
for i in range(1):
if n2/c2 <= 0.11:
comp_list.append(c2)
comp_list.append(n2)
if c3/c2 <= 0.26:
comp_list.append(c3)
if ic4/c3 <= 0.27:
comp_list.append(ic4)
if nc4/ic4 <= 1:
comp_list.append(nc4)
if ic5/nc4 <= 0.06:
comp_list.append(ic5)
if nc5/ic5 <= 0.25:
comp_list.append(nc5)
sum = n2+c2+c3+ic4+nc4+ic5+nc5
c1 = 100-sum
comp_list.append(c1)
df = pd.Series(comp_list)
print df
However, when i run the code, the amount of numbers outputted is not consistent and can range from 3 to 5. for example, 1 run would give me:
0 1.560
1 0.251
2 0.008
3 86.665
a second run would give me:
0 12.929
1 1.015
2 2.126
3 0.093
4 0.0025
5 83.376
I have no idea why the output is not consistent.
Maybe I need to iterate through a random distribution until all the if statements are satisfied? or am I missing something obvious?
Aucun commentaire:
Enregistrer un commentaire