get average of matrix