Lecture
Aggregation Functions (sum, mean, std, etc.)
NumPy provides built-in functions that make it easy to summarize and analyze data in arrays.
With just one line of code, you can calculate totals, averages, minimums, maximums, and more.
Common Aggregation Functions
np.sum(): total of all valuesnp.mean(): average valuenp.min(): smallest valuenp.max(): largest valuenp.std(): standard deviationnp.median(): middle value (helpful for distributions)
Axis Support
Aggregation functions can summarize an entire array or operate along a specific axis for row-wise or column-wise results.
axis=0: column-wiseaxis=1: row-wise
Aggregation Functions
arr = np.array([[1, 2], [3, 4]]) print(arr.sum()) # Sum of all elements print(arr.sum(axis=0)) # Sum down columns → [4 6] print(arr.sum(axis=1)) # Sum across rows → [3 7]
Lessons in this chapter · NumPy Essentials for Data Analysis
- 1. What is NumPy and Why Use It?
- 2. Creating 1D and 2D Arrays
- 3. Indexing and Slicing Arrays
- 4. Array Arithmetic and Broadcasting
- 5. Boolean Masking and Filtering
- 6. Array Shapes, Axes, and Broadcasts
- 7. Multiple-choice quiz
- 8. Aggregation Functions (sum, mean, std, etc.)
- 9. Array Reshaping and Flattening
- 10. Generating Arrays (arange, linspace, zeros, ones)
- 11. Data Type Conversion and Copying Arrays
- 12. Working with Multidimensional Arrays
- 13. Fill-in-the-blank quiz
Quiz
0 / 1
Which NumPy aggregation function calculates the average value of an array?
np.sum()
np.min()
np.mean()
np.std()
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help