#! /usr/bin/env python # def r8col_mean ( m, n, a ): #*****************************************************************************80 # ## R8COL_MEAN returns the column means of an R8COL. # # Discussion: # # An R8COL is an M by N array of R8's, regarded as an array of N columns, # each of length M. # # Example: # # A = # 1 2 3 # 2 6 7 # # MEAN = # 1.5 4.0 5.0 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 25 February 2016 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, N, the number of rows and columns. # # Input, real A(M,N), the array to be examined. # # Output, real MEAN(N), the means, or averages, of the columns. # import numpy as np mean = np.zeros ( n ) for j in range ( 0, n ): for i in range ( 0, m ): mean[j] = mean[j] + a[i,j] for j in range ( 0, n ): mean[j] = mean[j] / float ( m ) return mean def r8col_mean_test ( ): #*****************************************************************************80 # ## R8COL_MEAN_TEST tests R8COL_MEAN # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 25 February 2016 # # Author: # # John Burkardt # import numpy as np from r8col_print import r8col_print from r8vec_print import r8vec_print m = 3 n = 4 print '' print 'R8COL_MEAN_TEST' print ' For an R8COL, an array of column vectors' print ' R8COL_MEAN computes means' a = np.zeros ( [ m, n ] ) k = 0 for i in range ( 0, m ): for j in range ( 0, n ): k = k + 1 a[i,j] = k r8col_print ( m, n, a, ' The array:' ) mean = r8col_mean ( m, n, a ) r8vec_print ( n, mean, ' Column means:' ) # # Terminate. # print '' print 'R8COL_MEAN_TEST' print ' Normal end of execution.' return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) r8col_mean_test ( ) timestamp ( )