#! /usr/bin/env python # def r8row_sum ( m, n, a ): #*****************************************************************************80 # ## R8ROW_SUM returns the sums 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: # # 27 February 2016 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, N, the number of rows and columns. # # Input, real A(M,N), the R8ROW # # Output, real ROW_SUM(M), the sum of the entries of # each row. # import numpy as np row_sum = np.zeros ( m ) for i in range ( 0, m ): for j in range ( 0, n ): row_sum[i] = row_sum[i] + a[i,j] return row_sum def r8row_sum_test ( ): #*****************************************************************************80 # ## R8ROW_SUM_TEST tests R8ROW_SUM # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 27 February 2016 # # Author: # # John Burkardt # import numpy as np from r8row_print import r8row_print from r8vec_print import r8vec_print m = 3 n = 4 print '' print 'R8ROW_SUM_TEST' print ' R8ROW_SUM computes sums of an R8ROW.' 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] = float ( k ) r8row_print ( m, n, a, ' The matrix:' ) rowsum = r8row_sum ( m, n, a ) r8vec_print ( m, rowsum, ' The row sums:' ) # # Terminate. # print '' print 'R8ROW_SUM_TEST:' print ' Normal end of execution.' return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) r8row_sum_test ( ) timestamp ( )