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

performing operations on values in 2-D list and appending each sub-list to new list

I have two 2-D python array lists. I want to on each value in each array perform an operation on each other and append that value into a list while retaining the 2-D structure.

For example I have

list1 = [[1,2,3],[4,5,6],[7,8,9]]
list2 = [[3,2,1],[6,5,4],[9,8,7]]

I want to do so that (for example just simple addition) the output is

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

output_list: [[4,4,4],[10,10,10],[16,16,16]]

In my case, I am calculating the standard deviation.

I have two 2-D lists named rolling_mean and mean_std that I am doing parallel iteration over and appending to an list named lower_bound

lower_bound = []
    

    for k,h in zip(range(len(rolling_mean)),range(len(mean_std))):
        for l,m in zip(range(len(rolling_mean[k])),range(len(mean_std[h]))):
            lower_bound.append(rolling_mean[k][l] - (1.96 * mean_std[h][m]))

    print(lower_bound)

This is giving me the correct output but the values are all in one single array. I want it to be a 2-D array like the example output above.

>Solution :

...
lb_part = []
for l,m ...
    lb_part.append(...)
lower_bound.append(lb_part)
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