title: Gaussian elimination - pivoting using slicing in python
body: <p>I'm trying to implement pivoting for the Gaussian elimination in Python and face some problems.</p>
  
  <pre><code>def pivot2(matrix,i):
      # matrix is a N*N matrix
      # i is the column I want to start with
  
      m = matrix.shape[1]
      for n in range(i,m):
          colMax = np.argmax(abs(matrix[n:,i]), axis=0) #rowindex of highest absolute value in column
          if(colMax == 0): #if max in column is in first row, stop
              break;
          tmpRow = copy.copy(matrix[n,:]) #create new object of same row
          matrix[n,:] = matrix[colMax,:]  #overwrite first row with row of max value
          matrix[colMax,:] = tmpRow       #overwrite old row of max value
      return matrix
  </code></pre>
  
  <p>The code works for <code>i=0</code> just fine. However for <code>i=1</code> I can't search for the index of the maximum value in the whole column because it will obviously always be <code>0</code>.</p>
  
  <p>When I slice this matrix from a 3x3 matrix:</p>
  
  <pre><code>array([[ 1.,  2.],
         [-3., -2.]])
  </code></pre>
  
  <p>and use my <code>argmax</code> function, the index is <code>1</code>. But in my original matrix the index of the same row is 2 and it swaps the wrong rows. How do I fix this?</p>
  
  <p>And is there a simpler way to implement pivoting using slices?</p>