text: Find the mean vector of a Matrix | Javascript program to find mean vector of given matrix ; Function to find mean vector ; Loop to traverse each column ; To calculate mean of each row ; to store sum of elements of a column ; Driver code
code: var rows = 3 ; var cols = 3 ; function meanVector ( mat ) { document . write ( " " ) ; for ( var i = 0 ; i < rows ; i ++ ) { var mean = 0.00 ; var sum = 0 ; for ( var j = 0 ; j < cols ; j ++ ) sum += mat [ j ] [ i ] ; mean = sum / rows ; document . write ( mean + " " ) ; } document . write ( " " ) ; } var mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; meanVector ( mat ) ;