'Get element wise average of multiple arrays [duplicate]
I have a numpy.ndarray that is made up of other arrays all of the same length. For example:
array_1 = [[3,5,6.2],
[2,4.1,10],
[3,3.5,4]]
How can I get averages element wise. So as to return a single array where each element is the average of the respective elements across all the sub arrays in array_1? So it would return:
averaged_array = [2.66, 4.2, 6.733]
Solution 1:[1]
to obtain the average for each list in the matrix:
averaged_array = np.array(array_1).mean(axis=1)
to obtain the average for each column:
averaged_array = np.array(array_1).mean(axis=0)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Salvatore Daniele Bianco |
