0

These are my arrays

image =  [[0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,1,1,1,1,1,1,0,0],
          [0,0,1,1,1,1,1,1,0,0],
          [0,0,1,1,1,1,1,1,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0] 
           ]
image1 = [[0,0,0,0,0,0,0,0,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0] 
           ]

I want to get the average of each element from the different arrays and make a list of new averages, please help

This is what I have done so far: enter image description here

3 Answers3

2
import numpy as np
ans = (np.array(image) + np.array(image1))/2.0
ans = ans.tolist()

but it seems to be a duplicate question Average values in two Numpy arrays

Geneva
  • 156
  • 2
1

Numpy ninja code.

import numpy as np
image =  [[0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,1,1,1,1,1,1,0,0],
          [0,0,1,1,1,1,1,1,0,0],
          [0,0,1,1,1,1,1,1,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0] 
           ]
image1 = [[0,0,0,0,0,0,0,0,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0],
          [0,0,1,0,0,0,1,1,0,0] 
           ]
images = [image,image1]
np.array(images).mean(axis=0)
Mont
  • 164
  • 1
  • 4
0

In addition to the other answers, your code would have worked as following:

imagi = []
for x, y in zip(img, img1):
    z = (x + y) / 2
    imagi.append(z)
AcK
  • 2,063
  • 2
  • 20
  • 27