#! /usr/bin/env python # def r8row_swap ( m, n, a, irow1, irow2 ): #*****************************************************************************80 # ## R8ROW_SWAP swaps two rows 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: # # 28 February 2016 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, N, the number of rows and columns. # # Input, real A(M,N), the R8ROW. # # Input, integer IROW1, IROW2, the two rows to swap. # 0 <= IROW1, IROW2 < M. # # Output, real A(M,N), the array after row swapping. # from sys import exit if ( irow1 < 0 or m <= irow1 ): print '' print 'R8ROW_SWAP - Fatal error!' print ' IROW1 is out of range.' exit ( 'R8ROW_SWAP - Fatal error!' ) if ( irow2 < 0 or m <= irow2 ): print '' print 'R8ROW_SWAP - Fatal error!' print ' IROW2 is out of range.' exit ( 'R8ROW_SWAP - Fatal error!' ) if ( irow1 == irow2 ): return a for j in range ( 0, n ): t = a[irow1,j] a[irow1,j] = a[irow2,j] a[irow2,j] = t return a def r8row_swap_test ( ): #*****************************************************************************80 # ## R8ROW_SWAP_TEST tests R8ROW_SWAP # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 February 2016 # # Author: # # John Burkardt # import numpy as np from r8row_print import r8row_print m = 3 n = 4 print '' print 'R8ROW_SWAP_TEST' print ' R8ROW_SWAP swaps two rows 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] = k r8row_print ( m, n, a, ' The original matrix:' ) row1 = 0 row2 = 2 print '' print ' Swap rows %d and %d' % ( row1, row2 ) a = r8row_swap ( m, n, a, row1, row2 ) r8row_print ( m, n, a, ' The modified matrix:' ) # # Terminate. # print '' print 'R8ROW_SWAP_TEST:' print ' Normal end of execution.' return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) r8row_swap_test ( ) timestamp ( )