I want to implement my own LU decomposition P,L,U = my_lu(A), so that given a matrix A, computes the LU decomposition with partial pivoting. But I only know how to do it without pivoting. Can anyone help to do the partial pivoting?
def lu(A):
import numpy as np
# Return an error if matrix is not square
if not A.shape[0]==A.shape[1]:
raise ValueError("Input matrix must be square")
n = A.shape[0]
L = np.zeros((n,n),dtype='float64')
U = np.zeros((n,n),dtype='float64')
U[:] = A
np.fill_diagonal(L,1) # …Run Code Online (Sandbox Code Playgroud)