code: def swap_across(idx, idy, mat_a, mat_r, perm):
      
      # Temporary permutation matrix for swaping 2 rows or columns.
      size = mat_a.shape[0]
      perm_new = numpy.eye(size, dtype=int)
  
      # Modify the permutation matrix perm by swaping columns.
      perm_row = 1.0*perm[:, idx]
      perm[:, idx] = perm[:, idy]
      perm[:, idy] = perm_row
  
      # Modify the permutation matrix p by swaping rows (same as
      # columns because p = pT).
      row_p = 1.0 * perm_new[idx]
      perm_new[idx] = perm_new[idy]
      perm_new[idy] = row_p
  
      # Permute mat_a and r (p = pT).
      mat_a = numpy.dot(perm_new, numpy.dot(mat_a, perm_new))
      mat_r = numpy.dot(mat_r, perm_new)
      return mat_a, mat_r, perm
docs: Interchange row and column idy and idx.