what is the calculation behind vector matrix::Average()

 


Hello, I am testing the functions with vectors and matrices a little and initially I have encountered this problem
I don't know what the formula is behind the result that this function gives me.

I thought it was a weighted average, but the result does not coincide except in 2 elements
As an example I am using this code:

   matrixf matrix_a= {{10,3,2},{1,8,12},{6,5,4},{7,11,9}};
   matrixf matrix_w={{2,2,3},{2,3,4},{3,4,5},{4,5,6}};
   Print("matrix_a\n",matrix_a);
   Print("********************");
   Print("matrix_w\n",matrix_w);


   vectorf cols_average=matrix_a.Average(matrix_w,0);
   vectorf rows_average=matrix_a.Average(matrix_w,1);
   float matrix_average=matrix_a.Average(matrix_w);

   Print("cols_average ",cols_average);
   Print("rows_average ",rows_average);
   Print("average value  ",matrix_average);


//cols_average [6.181818,7.5,7.1111112]
//rows_average [4.5714288,8.2222223,4.7272725,9.4615383]
//average value  7.0



My manual formula to check the result is to multiply base by weight and divide by sum of weights, which based on the information in the first row is as follows:
(10*2 + 3*2 + 2*3)/(2+2+3) = 4.5714 which matches the value of rows_average[0]

If I take the same concept to the second row it would be:

(1*2 + 8*3+ 12*4)/(2+3+4) = 8.222 which matches the value of rows_average[1]

Now, if I take the same concept to the third row it would be

(6*3 + 5*4 + 4*5) /(3+4+5) = 4.8333 and this does not match the value of rows_average[2], nor does it match the process in row 4


I'm not thinking of a mistake, of course not,

I am asking what I am doing wrong or what is the formula that helps me interpret the process

thank you so much


Note; I Did not test the columns results, I only tried to understand the rows results

 
Has anyone had a chance to review it? Can you give me a hand to know if I am making a bad interpretation of the included library?


Thank you for read it 

 
I controlled and all I can say is it is strange. It looks like a bug!
 
Yashar Seyyedin #:
I controlled and all I can say is it is strange. It looks like a bug!

Thanks for to check it.
I Think the same. can be a bug