I wanted to address this to the professor or whoever is good at Python coding. I am a beginner in coding and welcome to feedback.
In the solutions section, firstly for question 6 to find sachin’s average score for each quartile of India’s score. I was able to code a faster solution as below without using specific indices and reshaping.
india_data = cric_data[:, 2] Q1 = np.percentile(india_data, 25) Q2 = np.percentile(india_data, 50) Q3 = np.percentile(india_data, 75) Q4 = np.percentile(india_data, 100) np.mean(sachin_data[india_data<Q1]) np.mean(sachin_data[india_data<Q2]) np.mean(sachin_data[india_data<Q3] np.mean(sachin_data[india_data<Q4])
The logic was simple here and we made use of broadcasting and it actually worked without reshaping arrays. This becomes much more useful in problem 8, where the solution is a 2 liner.
To find average of sachin’s score after he scores a given x
def sachin_avg(x): return np.mean(sachin_data[sachin_data>=x]) - x
This can return value for any x entered. Request your thoughts, suggestions and explanation.