Np.mean() VS np.average()

Hi everyone,

Got a very quick question about the `mean` and `average` in Python NumPy.

While going through the Data Science course, they mentioned using `np.average()` to find the mean… but a little bit further down the road the Hint in an exercise (Variance in Weather, Task 4) suggested me to use `np.mean()`.

So I’m a little bit confused as to when I should use `np.average()` and `np.mean()` and what actually the difference is between the two. Since they both seem to do the same thing.

Thanks!

This is definitely a query where it’s worth looking at the docs since they are quite similar.

There’s some slight differences in the possible parameters but the biggest difference is that np.avereage allows weights to be supplied for each of the values so its purpose is to compute the weighted average. If you’re just after the mean I’d suggest sticking with mean since it’s clear what you mean-
https://numpy.org/doc/stable/reference/generated/numpy.mean.html
https://numpy.org/doc/stable/reference/generated/numpy.average.html

2 Likes