Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get element wise average of multiple arrays

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]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading