You can create a 3D array containing your 2D arrays to be averaged, then average along axis=0 using np.mean or np.average (the latter allows for weighted averages):

np.mean( np.array([ old_set, new_set ]), axis=0 )

This averaging scheme can be applied to any (n)-dimensional array, because the created (n+1)-dimensional array will always contain the original arrays to be averaged along its axis=0.

Answer from Saullo G. P. Castro on Stack Overflow
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-158.php
Python NumPy: Calculate average values of two given numpy arrays - w3resource
August 29, 2025 - Implement a solution that uses np.mean on the stack of two arrays along a new axis to compute the average.
Discussions

python - Weighted average element-wise between two arrays - Stack Overflow
I have two arrays of number and I want to compute a weighted average element-wise between these array and store it in a new array. The solution I use for now is : array_1 = [0,1,2,3,4] array_2 =... More on stackoverflow.com
🌐 stackoverflow.com
python - How to calculate Average of n numpy arrays - Stack Overflow
I have 'n' numpy arrays each with shape (128,) How to get an average numpy array of shape (128,) for the list of numpy arrays. I have seen the documentation of numpy's average() and mean() which More on stackoverflow.com
🌐 stackoverflow.com
How can I average an array of arrays in python? - Stack Overflow
I have a simulation that runs over many times. Each time an array is produced and I insert it into a larger array keeping track of all the data. for example record = [] for i in range(2): r = More on stackoverflow.com
🌐 stackoverflow.com
Average multiple arrays in loop
Hello everyone, I have some images and for each image I calculate an array using a function in a loop. Is there a way to make the average of the arrays I created to have one array for all the images? What I was thinking is to store each array in a big array (WHICH FUNCTION?) with total length ... More on forum.image.sc
🌐 forum.image.sc
7
0
July 5, 2017
🌐
IncludeHelp
includehelp.com › python › calculate-average-values-of-two-given-numpy-arrays.aspx
Python - Calculate average values of two given NumPy arrays
Suppose we have a series of numbers from 1 to 10, then the average of this series will be: ∑x = 1+2+3+4+5+6+7+8+9+10 ∑x = 55 n = 10 x̄ = 55/10 x̄ = 5.5 ... # Import numpy import numpy as np # Creating two numpy arrays arr1 = [[0, 1], [4, 5]] arr2 = [[2, 7], [0, 1]] # Display original ...
🌐
Bobby Hadz
bobbyhadz.com › blog › calculate-average-of-2-numpy-arrays
Calculate the average (mean) of 2 NumPy arrays | bobbyhadz
April 12, 2024 - Copied!import numpy as np arr1 ... # 👇️ [3. 4. 5. 6.] print(arr3) ... We used the addition (+) operator to sum the two arrays element-wise and then divided by 2. The average (or mean) of 2 NumPy arrays is calculated ...
🌐
Finxter
blog.finxter.com › home › learn python blog › how to calculate the average of a numpy 2d array?
How to Calculate the Average of a NumPy 2D Array? - Be on the Right Side of Change
November 11, 2023 - When applied to a 2D array, NumPy simply flattens the array. The result is the average of the flattened 1D array. Only if you use the optional axis argument, you can average along the rows or columns of the 2D array.
🌐
Python Examples
pythonexamples.org › python-numpy-average
Average of NumPy Array - Examples
To find the average of a NumPy array, you can use the numpy.average() statistical function.
🌐
pythontutorials
pythontutorials.net › blog › average-values-in-two-numpy-arrays
How to Calculate Element-Wise Average of Two Numpy Arrays: Example & Syntax Guide — pythontutorials.net
The most intuitive way is to add the two arrays element-wise and then divide by 2. NumPy natively supports element-wise addition with the + operator, and scalar division with /. ... Dividing the result by 2 scales each sum to an average.
Find elsewhere
Top answer
1 of 4
3

Just use NumPy's vectorised operations. To do so, first convert your lists to arrays and then just multiply each array with the respective weight and take the sum

import numpy as np

array_1 = np.array([0,1,2,3,4])
array_2 = np.array([2,3,4,5,6])

weight_1 = 0.5
weight_2 = 0.5

array_3 = weight_1*array_1 + weight_2*array_2
# array([1., 2., 3., 4., 5.])

A direct NumPy solution using np.average would be the following, where axis=0 means take the average row wise (using both columns). np.vstack() simply stacks the two arrays vertically.

np.average(np.vstack((array_1, array_2)), axis=0, weights=[weight_1, weight_2])

As pointed out by @yatu, you can also pass a list of your arrays and specify the axis

np.average([array_1, array_2], axis=0, weights=[weight_1, weight_2])

Timing comparison inspired by the comments on @yatu's answer: As you can see, list comprehension and zip is slightly faster here but then this performance is for small arrays. I am sure, for large arrays, the vectorised solution will take over

Devesh's method

%timeit result = [ item1 * weight_1 + item2 * weight_2 for item1, item2 in zip(array_1, array_2)]
# 25.5 µs ± 3.75 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

%timeit np.average([array_1, array_2], axis=0, weights=[weight_1, weight_2])
# 42.9 µs ± 2.94 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

%timeit np.average(np.vstack((array_1, array_2)), axis=0, weights=[weight_1, weight_2])
# 44.8 µs ± 4.98 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
2 of 4
3

You can zip both iterators, and multiply each element with the corresponding weight

array_1 = [0,1,2,3,4]
array_2 = [2,3,4,5,6]

weight_1 = 0.5
weight_2 = 0.5

#Zip both iterators and multiply weight with corresponding item
result = [ item1 * weight_1 + item2 * weight_2 for item1, item2 in zip(array_1, array_2)]
print(result)

The output will be

[1.0, 2.0, 3.0, 4.0, 5.0]
🌐
Iditect
iditect.com › programming › python-example › calculate-average-values-of-two-given-numpy-arrays.html
Calculate average values of two given NumPy arrays
To calculate the average values of two given NumPy arrays, you can simply add the arrays element-wise and then divide by 2.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.average.html
numpy.average — NumPy v2.5 Manual
The array of weights must be the same shape as a if no axis is specified, otherwise the weights must have dimensions and shape consistent with a along the specified axis. If weights=None, then all data in a are assumed to have a weight equal to one. The calculation is: ... where the sum is over all included elements. The only constraint on the values of weights is that sum(weights) must not be 0. ... Default is False. If True, the tuple (average, sum_of_weights) is returned, otherwise only the average is returned.
🌐
University of Texas at Austin
het.as.utexas.edu › HET › Software › Numpy › reference › generated › numpy.average.html
numpy.average — NumPy v1.9 Manual
numpy.average(a, axis=None, weights=None, returned=False)[source]¶ · Compute the weighted average along the specified axis. See also · mean · ma.average · average for masked arrays – useful if your data contains “missing” values · Examples · >>> data = range(1,5) >>> data [1, 2, 3, 4] >>> np.average(data) 2.5 >>> np.average(range(1,11), weights=range(10,0,-1)) 4.0 ·
🌐
Programiz
programiz.com › python-programming › numpy › methods › average
NumPy average()
The numpy.average() method returns the weighted average of the array.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.average.html
numpy.average — NumPy v2.2 Manual
The array of weights must be the same shape as a if no axis is specified, otherwise the weights must have dimensions and shape consistent with a along the specified axis. If weights=None, then all data in a are assumed to have a weight equal to one. The calculation is: ... where the sum is over all included elements. The only constraint on the values of weights is that sum(weights) must not be 0. ... Default is False. If True, the tuple (average, sum_of_weights) is returned, otherwise only the average is returned.
🌐
Finxter
blog.finxter.com › home › learn python blog › numpy average
NumPy Average – Be on the Right Side of Change
January 26, 2021 - NumPy is a popular Python library for data science focusing on arrays, vectors, and matrices. It’s at the core of data science and machine learning in Python. In today’s article, you’ll going to master NumPy’s impressive average() function that will be a loyal friend to you when fighting your upcoming data science battles. average(a, axis=None, ... Read more
🌐
Image.sc
forum.image.sc › usage & issues
Average multiple arrays in loop - Usage & Issues - Image.sc Forum
July 5, 2017 - What I was thinking is to store ... make the mean of the elements 0: (array length+i):total length (from 0 to total length with array length +i step), where i =( 0,1,2,3…array length)....
🌐
SciPy
docs.scipy.org › doc › numpy-1.13.0 › reference › generated › numpy.average.html
numpy.average — NumPy v1.13 Manual
>>> data = np.arange(6).reshape((3,2)) >>> data array([[0, 1], [2, 3], [4, 5]]) >>> np.average(data, axis=1, weights=[1./4, 3./4]) array([ 0.75, 2.75, 4.75]) >>> np.average(data, weights=[1./4, 3./4]) Traceback (most recent call last): ... TypeError: Axis must be specified when shapes of a and weights differ. numpy.median ·
🌐
Vultr Docs
docs.vultr.com › python › third party › numpy › average()
Python Numpy average() - Compute Mean Value
November 11, 2024 - Compute the weighted average using the average() function. ... import numpy as np data = np.array([10, 20, 30, 40, 50]) weights = np.array([1, 2, 3, 4, 5]) weighted_mean = np.average(data, weights=weights) print(weighted_mean)