How to find the grouped mean in numpy? Grouped mean as we all know that what is mean which nothing but the sum of all elements divided by total number of elements. A grouped is nothing but the mean of the data which is placed in intervals or we can say mean of grouped data. For this the individual values are not available and we are also not able to calculate there sum unlike the other listed data. For calculating the grouped mean firstly we have to determine the midpoint of each class then these midpoints is going to be multiplied with frequencies of the corresponding intervals or classes. Then the sum of the products divided by the total number of values will be the value of mean.
import numpy as np
Sample_array = np.array([[11,22,35],[45,55,65],[75,85,95]]) print("This is a Sample array:","\n",Sample_array)
This is a Sample array: [[11 22 35] [45 55 65] [75 85 95]]
print("The mean of each row is:","\n",Sample_array.mean(axis=1), "\n") print("The mean of each column is:","\n",Sample_array.mean(axis=0))
The mean of each row is: [22.66666667 55. 85. ] The mean of each column is: [43.66666667 54. 65. ]