![]() |
VOOZH | about |
Filtering and aggregating data with NumPy focuses on selecting required elements from arrays and computing summary values such as sum, mean or minimum. These operations are commonly used to analyze numerical data efficiently using simple NumPy functions.
Filtering data in NumPy is done using boolean conditions applied directly to arrays. The result is a new array containing only those elements that satisfy the given condition.
1. Values Above a Limit: This operation selects all elements whose values are greater than a given number.
[ 7 6 8 10 6 9 10 9 6 6]
2. Even-Valued Elements: This approach extracts only those elements that are evenly divisible by 2.
[ 4 2 2 4 2 10 10 4 8 8 4 2 6]
3. Multiple Conditions Combined: This method selects elements that satisfy more than one condition at the same time.
[ 6 8 10 8 10]
4. Divisibility-Based Selection: This technique selects elements divisible by at least one of the specified numbers.
[9 9 9 9 6 7 3 3 9]
5. Boolean Mask from Another Array: This method uses a separate boolean array to select specific rows.
[[ 9 5 2 5 8] [10 3 1 5 3] [ 5 10 1 6 4]]
6. Condition Applied to a Single Row: This approach filters elements from a specific row based on a condition.
[6 8 7]
Aggregation in NumPy refers to computing summary statistics over arrays. Functions such as sum, mean, standard deviation, minimum and maximum help analyze data across the entire array or along specific axes.
1. Total Sum: This operation calculates the sum of all elements in an array and also demonstrates how summation works along rows and columns.
15 21 [5 7 9] [ 6 15]
2. Average Value: This operation computes the mean (average) of array elements across the entire array or along a specified axis.
3.0 3.5 [2.5 3.5 4.5] [2. 5.]
3. Spread of Values: This operation measures how much the values in the array vary from the mean using standard deviation.
1.4142135623730951 1.707825127659933 [1.5 1.5 1.5] [0.81649658 0.81649658]
4. Smallest and Largest Values: These operations identify the minimum and maximum values present in the array.
1 1 [1 2 3] [1 4] -------------------- 5 6 [4 5 6] [3 6]