Per-Student Averages
Intermediate · Write the code · from NumPy Operations: Element-wise Math, Aggregations, and ufuncs
From the lesson: NumPy Operations: Element-wise Math, Aggregations, and ufuncs
You know how to create NumPy arrays. Now it's time to actually do things with them. The real power of NumPy is that you can perform math on entire arrays at once - no loops required.
Read the lessonCreate a 3x4 grades matrix:
[[85, 90, 78, 92],
[70, 88, 95, 80],
[92, 76, 84, 88]]Print the average score for each student (each row) using the axis parameter. Round to 1 decimal place.
import numpy as np
grades = np.array([[85, 90, 78, 92],
[70, 88, 95, 80],
[92, 76, 84, 88]])
# Print per-student average, rounded to 1 decimal
More NumPy Operations exercises
- Apply Sales TaxIntermediate
- Student Grade SummaryIntermediate
- Filter the Hot DaysIntermediate
- Predict the ufunc OutputIntermediate
- Rank the Top 3 ScoresIntermediate
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz