How to find the grouped mean in numpy?

This recipe helps you find the grouped mean in numpy

Recipe Objective

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.

Step 1 - Import library

import numpy as np

Step 2 - Take Sample array

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]]

Step 3 - Find the Grouped mean

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.        ]

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

Create Your First Chatbot with RASA NLU Model and Python
Learn the basic aspects of chatbot development and open source conversational AI RASA to create a simple AI powered chatbot on your own.

Learn How to Build PyTorch Neural Networks from Scratch
In this deep learning project, you will learn how to build PyTorch neural networks from scratch.

GCP MLOps Project to Deploy ARIMA Model using uWSGI Flask
Build an end-to-end MLOps Pipeline to deploy a Time Series ARIMA Model on GCP using uWSGI and Flask

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Learn to Build Generative Models Using PyTorch Autoencoders
In this deep learning project, you will learn how to build a Generative Model using Autoencoders in PyTorch

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Avocado Machine Learning Project Python for Price Prediction
In this ML Project, you will use the Avocado dataset to build a machine learning model to predict the average price of avocado which is continuous in nature based on region and varieties of avocado.

Hands-On Approach to Master PyTorch Tensors with Examples
In this deep learning project, you will learn how to perform various operations on the building block of PyTorch : Tensors.