Sort by

recency

|

123 Discussions

|

  • + 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))
    
  • + 0 comments

    Code in R:

    physics_scores <- c(15, 12, 8, 8, 7, 7, 7, 6, 5, 3) history_scores <- c(10, 25, 17, 11, 13, 17, 20, 13, 9, 15)

    correlation <- cor(physics_scores, history_scores)

    print(sprintf("%.3f", correlation)) It is giving correct value

  • + 0 comments

    Interface does not allow import of numpy. It appears others imported Python stdlib modules and some use non stdlib modules. How do we know which modules (if any) can be used to answer this question?

  • + 1 comment

    Why doesn't this code pass the test ?

    from scipy.stats import pearsonr
    
    physics_scores = [15, 12, 8, 8, 7, 7, 7, 6, 5, 3]
    history_scores = [10, 25, 17, 11, 13, 17, 20, 13, 9, 15]
    
    corr, p_value = pearsonr(physics_scores, history_scores)
    
    print(f"{corr:.3f}")
    
  • + 0 comments

    I have run time error