• + 0 comments

    I ultimately got the answer correct by hardcoding it in a plain text file. I'd still like to know why my code below isn't working. (Also, this text editor sucks!)

    import numpy as np 
    physics = np.array([15,12,8,8,7,7,7,6,5,3])
    history = np.array([10,25,17,11,13,17,20,13,9, 15])
    mean_physics = np.mean(physics)
    mean_history = np.mean(history)
    numerator = np.sum((physics - mean_physics)*(history - mean_history))
    sum_squares_physics = np.sqrt(np.sum((physics - mean_physics)**2))
    sum_squares_history = np.sqrt(np.sum((history - mean_history)**2))
    print(round(numerator / (sum_squares_history*sum_squares_physics),3))