chapter 3 numpy data analysis
chapter 3 numpy data analysis
Chapter 3
Introduction to NumPy
• • What is NumPy?
• • Importance of NumPy in Python for data
analysis and scientific computing
• • Key features: speed, efficiency, and array-
based operations
Numerical Python (NumPy)
• The NumPy ndarray object is a fast and flexible container for large
data sets in Python.
• NumPy arrays are a bit like Python lists, but are still a very different
beast at the same time.
• Arrays enable you to store multiple items of the same data type. It is
the facilities around the array object that makes NumPy so
convenient for performing math and data manipulations.
Overview of Mathematical Operations
• • Essential for data analysis
• • Efficiency of element-wise operations on
arrays
Basic Arithmetic Operations
• • np.add(), np.subtract(), np.multiply(),
np.divide()
• Example:
• import numpy as np
• a = np.array([1, 2, 3])
• b = np.array([4, 5, 6])
• print(np.add(a, b)) # Output: [5 7 9]
Advanced Mathematical Functions
• • np.power(), np.sqrt(), np.exp(), np.log()
• Efficient computation on large datasets
• Example:
• a = np.array([1, 4, 9, 16])
• print(np.sqrt(a)) # Output: [1. 2. 3. 4.]
Matrix Operations
• • np.dot() — Dot product
• • np.matmul() — Matrix multiplication
• Example:
• A = np.array([[1, 2], [3, 4]])
• B = np.array([[5, 6], [7, 8]])
• print(np.dot(A, B))
Importance of Statistical Functions
• • Analyzing and summarizing data
• • Understanding data distribution and trends
Basic Statistical Measures
• • np.mean(), np.median(), np.std(), np.var()
• Example:
• data = np.array([10, 20, 30, 40, 50])
• print(np.mean(data)) # Output: 30.0
Min, Max, and Sum Functions
• • np.min(), np.max(), np.sum()
• Used for performance metrics
Cumulative Functions
• • np.cumsum(), np.cumprod()
• Example:
• a = np.array([1, 2, 3])
• print(np.cumsum(a)) # Output: [1 3 6]
Why Sorting and Searching Matter
• • Organizing and retrieving data efficiently
• • Applications in data analysis and ML
Sorting Functions
• • np.sort(), np.argsort()
• Example:
• a = np.array([3, 1, 2])
• print(np.sort(a)) # Output: [1 2 3]
Searching Functions
• • np.where(), np.argmax(), np.argmin()
• Example:
• a = np.array([10, 20, 5, 30])
• print(np.argmax(a)) # Output: 3
Unique and Count Functions
• • np.unique()
• Efficient for cleaning and summarizing data
Understanding Array Shapes
• • Foundation of array operations
• • Importance of reshaping for compatibility
Shape and Dimension Functions
• • np.shape(), np.ndim(), np.size()
• Example:
• a = np.array([[1, 2], [3, 4]])
• print(np.shape(a)) # Output: (2, 2)
Real-World Applications
• • Data cleaning and preprocessing
• • Statistical analysis
• • Visualizing and summarizing data
• • Efficient modeling
Conclusion
• • Recap of key functions and their importance
• • How these categories work together
• • Questions and discussions