np.average takes an optional weight parameter. If it is not supplied they are equivalent. Take a look at the source code: Mean, Average

np.mean:

try:
    mean = a.mean
except AttributeError:
    return _wrapit(a, 'mean', axis, dtype, out)
return mean(axis, dtype, out)

np.average:

...
if weights is None :
    avg = a.mean(axis)
    scl = avg.dtype.type(a.size/avg.size)
else:
    #code that does weighted mean here

if returned: #returned is another optional argument
    scl = np.multiply(avg, 0) + scl
    return avg, scl
else:
    return avg
...
Answer from Hammer on Stack Overflow
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Sum, mean, max, min for entire array, column/row-wise | note.nkmk.me
January 20, 2024 - NumPy allows you to calculate the sum, average, maximum, and minimum of an array (ndarray) using functions such as np.sum(), np.mean(), np.max(), and np.min() · These functions allow you to specify the axis argument to obtain results for each column (column-wise) or each row (row-wise).
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.mean.html
numpy.mean — NumPy v2.5 Manual
Compute the arithmetic mean along the specified axis · Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs
Discussions

Typeerror on "np.mean" function, any ways on how to fix?
np.mean() clearly doesnt like whatever data type Y contains. you could try some reflection to find out what type that is print(Y[0]) print(type(Y[0]) my guess is it probably ended up as a strings or something, which you would solve by casting it back to floats again with Y.astype('float') More on reddit.com
🌐 r/learnpython
7
1
June 19, 2022
Alternative to np.mean() with better performance?
There is almost never a reason to take a mean on a vector so large that run time is a concern except for if the distribution of values has a near infinite/undefined standard deviation. Do this: randomly sample 100000 (or 10000) points from the vector. (Numpy random choice) Take the mean. Observe it is basically the same value as the full data sample. The sample mean converges rapidly with the population mean under a general set of conditions. And for most applications a big sample will suffice. So anyway I question the need to calculate a mean that takes numpy 5 seconds. More on reddit.com
🌐 r/learnpython
32
9
November 27, 2023
find mean of 2 numpy arrays without using the 0 values
I'd set 0 values to nan and then use np.nanmean More on reddit.com
🌐 r/learnpython
18
3
April 8, 2023
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.nanmean.html
numpy.nanmean — NumPy v2.6.dev0 Manual
Compute the arithmetic mean along the specified axis, ignoring NaNs · Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs
🌐
Programiz
programiz.com › python-programming › numpy › methods › mean
NumPy mean()
The mean() method computes the arithmetic mean of a given set of numbers along the specified axis. The mean() method computes the arithmetic mean of a given set of numbers along the specified axis. import numpy as np # create an array array1 = np.array([0, 1, 2, 3, 4, 5, 6, 7]) # calculate ...
🌐
Reddit
reddit.com › r/learnpython › typeerror on "np.mean" function, any ways on how to fix?
r/learnpython on Reddit: Typeerror on "np.mean" function, any ways on how to fix?
June 19, 2022 -

So I'm currently working on a linear regression algorithm and whilst writing the code for it I encountered a typeerror on the "np.mean" function. (made in jupyter nb, so if this is related with updates or something, let me know.)

Here's the reproducible error code:

# Mean X and Y
mean_x = np.mean(X)
mean_y = np.mean(Y)

# Total number of values
m = len(X)

# Using the formula to calculate b1 and b0
numer = 0
denom = 0
for i in range(m):
    numer +- (x[i] - mean_x) * (Y[i] - mean_y)
    denom +- (X[i] - mean_x) ** 2
b1 = numer/denom
b0 = mean_y - (b1 * mean_x)

# Print coefficients
print(b1, b0) 

Here's the error screenshot:
https://imgur.com/P97plv3

P.S, I'm a complete newbie, so if I'm looking over something completely obvious, feel free to criticize me.

🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.nanmean.html
numpy.nanmean — NumPy v2.5 Manual
Compute the arithmetic mean along the specified axis, ignoring NaNs · Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs
Find elsewhere
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.mean.html
numpy.mean — NumPy v2.6.dev0 Manual
Compute the arithmetic mean along the specified axis · Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.mean.html
numpy.mean — NumPy v2.2 Manual
Compute the arithmetic mean along the specified axis · Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs
🌐
Programiz
programiz.com › python-programming › numpy › methods › nanmean
NumPy nanmean()
The numpy.nanmean() method computes the arithmetic mean along the specified axis, ignoring NaNs. The numpy.nanmean() method computes the arithmetic mean along the specified axis and ignores the NaNs (Not a Number).
🌐
Reddit
reddit.com › r/learnpython › alternative to np.mean() with better performance?
Alternative to np.mean() with better performance? : r/learnpython
November 27, 2023 - 1.1M subscribers in the learnpython community. Subreddit for posting questions and asking for general advice about all topics related to learning…
🌐
Codemia
codemia.io › home › knowledge hub › np.mean vs np.average in python numpy?
Codemia | Master System Design Interviews Through Active Practice
September 24, 2025 - np.mean and np.average both compute central tendency, but np.average supports explicit weighting. If no weights are provided, results are equivalent for...
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.nanmean.html
numpy.nanmean — NumPy v2.0 Manual
Compute the arithmetic mean along the specified axis, ignoring NaNs · Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs
🌐
Medium
medium.com › @heyamit10 › how-to-use-numpy-nanmean-to-calculate-the-mean-while-ignoring-nan-f5da3320be87
How to use numpy.nanmean() to Calculate the Mean While Ignoring nan | by Hey Amit | Medium
February 8, 2025 - How to use numpy.nanmean() to Calculate the Mean While Ignoring nan If you think you need to spend $2,000 on a 180-day program to become a data scientist, then listen to me for a minute. I understand …
🌐
Sharp Sight
sharpsight.ai › blog › numpy-mean
How to use the NumPy mean function - Sharp Sight
February 6, 2024 - This tutorial will show you how to use the NumPy mean function. You'll learn how compute the mean of NumPy 1-d arrays, 2-d arrays, and more ...
🌐
Interactive Chaos
interactivechaos.com › en › python › function › numpymean
numpy.mean | Interactive Chaos
January 21, 2019 - numpy.mean(a, axis=None, dtype=None, out=None, keepdims=False) · The numpy.mean function returns the average of the elements in array a. By default the average of the array is calculated once it is flattened. If an axis is specified, only that axis will be considered in the calculation
🌐
NumPy
numpy.org › doc › 1.21 › reference › generated › numpy.nanmean.html
numpy.nanmean — NumPy v1.21 Manual
Compute the arithmetic mean along the specified axis, ignoring NaNs · Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Functions ignoring NaN (np.nansum, np.nanmean, etc.) | note.nkmk.me
January 23, 2024 - In NumPy, functions like np.sum() and np.mean() return NaN if the array (ndarray) contains any NaN values. To perform calculations that ignore NaN, use functions such as np.nansum() and np.nanmean(). ...
🌐
AlgoCademy
algocademy.com › blog › understanding-np-mean-a-comprehensive-guide-to-calculating-averages-in-numpy
Understanding np.mean: A Comprehensive Guide to Calculating Averages in NumPy – AlgoCademy Blog
When working with numerical data in Python, calculating the mean (average) of values is one of the most common operations. NumPy, Python’s powerful numerical computing library, offers an efficient and versatile function for this purpose: np.mean(). Whether you’re analyzing scientific data, ...