#! /usr/bin/env python # def r8row_running_average ( m, n, v ): #*****************************************************************************80 # ## R8ROW_RUNNING_AVERAGE computes the running averages of an R8ROW. # # Discussion: # # An R8ROW is an M by N array of R8's, regarded as an array of M rows, # each of length N. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 25 February 2016 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, the number of rows. # # Input, integer N, the number of items in each row. # # Input, real V(M,N), the data. # # Output, real A(M,N+1), the running average. A(I,J) is the average value # of V(I,1:J-1). # import numpy as np a = np.zeros ( [ m, n + 1 ] ) # # Sum. # for j in range ( 1, n + 1 ): for i in range ( 0, m ): a[i,j] = a[i,j-1] + v[i,j-1] # # Average. # for j in range ( 1, n + 1 ): for i in range ( 0, m ): a[i,j] = a[i,j] / float ( j ) return a def r8row_running_average_test ( ): #*****************************************************************************80 # ## R8ROW_RUNNING_AVERAGE_TEST tests R8ROW_RUNNING_AVERAGE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 25 February 2016 # # Author: # # John Burkardt # from r8row_print import r8row_print from r8row_uniform_ab import r8row_uniform_ab print '' print 'R8ROW_RUNNING_AVERAGE_TEST' print ' R8ROW_RUNNING_AVERAGE returns M sets of running averages' print ' of an MxN R8ROW.' m = 5 n = 10 a = -5.0 b = +10.0 seed = 123456789 r, seed = r8row_uniform_ab ( m, n, a, b, seed ) r8row_print ( m, n, r, ' Random R8ROW:' ) s = r8row_running_average ( m, n, r ) r8row_print ( m, n + 1, s, ' Running averages:' ) # # Terminate. # print '' print 'R8ROW_RUNNING_AVERAGE_TEST:' print ' Normal end of execution.' return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) r8row_running_average_test ( ) timestamp ( )