I'm trying to calculate the np.sum of the elements within each array. I tried in stead of np.sum(outcome_list[0] == 'H' to just leave it as np.sum(outcome_list[j] == 'H' so that each "list" would have its own data set on the total number of heads, but it didn't like it. The bigger question is, how would I construct an array with a given base list and the action to be done in each element of that list?
EDIT:
the throw_a_coin definition
def throw_a_coin(N):
return np.random.choice(['H','T'], size=N)
N =40
trials (as shown above) is the set to be acted upon
for i in trials:
throws = throw_a_coin(i)
outcome_list.append(throws)
for j in outcome_list:
print("Number of Heads:", np.sum(outcome_list[0] == 'H'))
print (j)
EDIT 2:
problem resolved with the one shown below, however I'm getting more than 13 numbers for "probabilities" - it seems that the system is running through the trials list more than once.
def throw_a_coin(N):
return np.random.choice(['H','T'], size=N)
trials = [10, 30, 50, 70, 100, 130, 170, 200, 500, 1000, 2000, 5000, 10000]
for i in trials:
throws = throw_a_coin(i)
outcome_list.append(throws)
probabilities = []
for j in outcome_list:
print("Number of Heads:", np.sum(j == 'H'))
print("Number of Throws:", len(j))
print("p = Number of Heads/Total Throws:", (np.sum(j == 'H'))/len(j))
probabilities.append((np.sum(j =='H'))/len(j))
print (j)
print("\n")
print(probabilities)
