I need to calculate the average of the index of a matrix, using its closets ones. here an example.
A=[
[ 8.16666667 8.16666667 8.16666667 8.16666667 8.16666667 8.16666667]
[ 8.16666667 10. 8.16666667 8.16666667 8.16666667 8.16666667]
[ 8.16666667 8. 9. 8. 8.16666667 8.16666667]
[ 8.16666667 8.16666667 9. 5. 8.16666667 8.16666667]
[ 8.16666667 8.16666667 8.16666667 8.16666667 8.16666667 8.16666667]
[ 8.16666667 8.16666667 8.16666667 8.16666667 8.16666667 8.16666667]]
let's imagine that we have this matrix, and the next iteration i need to refresh this values with its averages. but the averages need to be calculated with the closets ones. if i take A[0][0]
its average must be,result =A[0][1]+A[1][0]/2
until here, no problem.
But now let's calculate the value in A[3][3]
position. result must be result = A[3][4]+A[3][2]+A[2][3]+A[4][3]/4
so, it's different.
The problem that i have is to design the algorithm to do this automatically, not only that but do it in an easy way for the pc. because I know that I can do it step by step in each position, but it will take too many lines of code. i'm using python for the calculates.
This is my first thought about it. see the image
divide it into sections and apply the algorithm to each condition.
But i think that it can be improved.