#! /usr/bin/env python
#
def r8col_sum ( m, n, a ):

#*****************************************************************************80
#
## R8COL_SUM sums the columns 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.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    26 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 COLSUM(N), the sums of the columns.
#
  import numpy as np

  colsum = np.zeros ( n )

  for j in range ( 0, n ):
    t = 0.0
    for i in range ( 0, m ):
      t = t + a[i,j]
    colsum[j] = t

  return colsum

def r8col_sum_test ( ):

#*****************************************************************************80
#
## R8COL_SUM_TEST tests R8COL_SUM
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    26 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_SUM_TEST'
  print '  For an R8COL, an array of column vectors'
  print '  R8COL_SUM computes sums'

  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:' )

  colsum = r8col_sum ( m, n, a )

  r8vec_print ( n, colsum, '  The column sums:' )
#
#  Terminate.
#
  print ''
  print 'R8COL_SUM_TEST'
  print '  Normal end of execution.'
  return

if ( __name__ == '__main__' ):
  from timestamp import timestamp
  timestamp ( )
  r8col_sum_test ( )
  timestamp ( )