0

I would like to take a 2D array, take the average in both the x- and y- direction, and then re-insert this back into the array (or create a new array with the answers). I found a way to do what I want with a 1D array / list : Take average of every 2 consecutive elements and insert them back into array

However, I want to do this with a 2D array. For example:

input array:

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

output_array:

[[1.0,1.5,2.0,2.5,3.0],
[2.5,3.0,3.5,4.0,4.5],
[4.0,4.5,5.0,5.5,6.0],
[5.5,6.0,6.5,7.0,7.5],
[7.0,7.5,8.0,8.5,9.0]]

What would be the best way of doing this?

Miss_Orchid
  • 308
  • 1
  • 8

0 Answers0