mercredi 22 mai 2019

What is going on here?!? I am about to lose my mind

I am running this python code mentioned below and the console says things like this:

sim is: [1 0 1 1 1 1 1 0 1 0]

counter_one is 3

counter_zero is 7

But which makes things even stranger is that when I run the code again every once in a while the counters are correct.

import numpy as np

from fractions import Fraction

elements = np.array([1, 0])

prob_of_functioning = Fraction(2, 3)
prob_of_failing = Fraction(1, 3)
probabilities = [prob_of_functioning, prob_of_failing]

sim = np.random.choice(elements, 10, p=probabilities)

print("sim is:")
print(sim)

counter_one = 0
counter_zero = 0

for k in sim:
    if sim[k] == 1:
        counter_one = (counter_one + 1)
    if sim[k] == 0:
        counter_zero = (counter_zero + 1)


print("counter_one is")
print(counter_one)

print("counter_zero is")
print(counter_zero)




Aucun commentaire:

Enregistrer un commentaire