Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I make a for statement work when comparing two apended lists?

The last for statement does not work. I am comparing the outputs of two functions (which are each being appended as a list). Essentially, if the output of the first item in the list for function A is larger than the first item in the list for function B then I would like to print a 1, if it is less then I would like to print 0, otherwise 0.5. However, when I run the code I get 1 for each value compares across both lists. This is false because I’ve manually checked each value (there should be 1s and 0s and no 0.5s).

from IPython.lib.display import IFrame
#Exptected Value

import numpy as np
import math
natural_log = np.log(1)


Outcomes = [[20, 0],[ 20, 0],[ 20, 0],[ 20, 0],[ 20, 0]]

Probabilities = [[0.001, 0.999],[  0.01, 0.99],[  0.1, 0.9],[  0.25, 0.75],[  0.5, 0.5]]


Y = []
PT= []

for i in range(0,len(Outcomes)):
    Y.append(Outcomes[i][0]*Probabilities[i][0] + Outcomes[i][1]*Probabilities[i][1])
    
for i in range(0,len(Outcomes)):
    PT.append((math.exp(-(-np.log(Probabilities[i][0]))**0.5))*(Outcomes[i][0]**0.5)+(math.exp(-(-np.log(Probabilities[i][1]))**0.5))*(Outcomes[i][1]**0.5))

for i in range(0,len(Outcomes)):
        if PT > Y:
            print("gamble",i+1,"PT output = 1")
        if PT < Y:
            print("gamble",i+1,"PT output = 0")
        if PT ==Y:
            print("gamble",i+1,"PT output = 0.5")

print(PT)
print(Y)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

try to modify following code to your requirement.

a=[1,2,3,4]
b=[1,3,2,1]

for i,j in zip(a,b):
    if i==j:
        print("it's a match.")
    else:
        print("not a match")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading