All problems
LU Pivot Swap Count
Problem
Perform Gaussian elimination with partial pivoting on A and return the number of row swaps performed.
At each column choose the row with the largest absolute pivot and swap it into position before eliminating below it. The swap count determines the sign of the permutation in a PLU factorization.
Hint
Each partial-pivot swap flips the sign of the determinant's permutation factor.
Test cases
case 1
in: [[[2,1],[1,3]]]
expected: 0
case 2
in: [[[1,3],[2,1]]]
expected: 1
case 3
in: [[[0,1],[1,0]]]
expected: 1
case 4
in: [[[1,2,3],[4,5,6],[7,8,9]]]
expected: 2
Starter codePython
def lu_pivot_swaps(A):
# Your code here
pass4 test cases · run your code against them in the editor