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

averaging every nth element of multiple lists

I have 4 lists of the same length and would like to average every nth element across the lists and make a new list out of these averaged values. As an example:

y1 = [1, 2, 2, 4, 5]
y2 = [3, 6, 9, 12, 0]
y3 = [2, 3, 4, 5, 6]
y4 = [2, 1, 5, 7, 9]

The expected result should be 
y1234  = [2 3 5 7 5]

How can I do this?

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 :

You can use numpy.mean

np.array([y1, y2, y3, y4]).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