I have the following piece of code where I compute the L matrix of a given square matrix using the command scipy.linalg.lu() and then I do the same thing again except then applied to the sparse form of the given matrix using scipy.sparse.linalg.splu(). This is the code:
import numpy as np
from scipy.sparse.linalg import splu
from scipy.sparse import csc_matrix
import scipy.linalg
A1 = csc_matrix([[1., 0, 0.], [5., 0, 2], [0, -1., 0]])
A2 = np.array([[1., 0, 0.], [5., 0, 2], [0, -1., 0]])
B = splu(A1)
P,L,U = scipy.linalg.lu(A2)
print(L);print(csr_matrix.todense(B.L))
Which returns the following:
[[ 1. 0. 0. ]
[ 0. 1. 0. ]
[ 0.2 -0. 1. ]]
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
As we can see, these matrices are not the same. Am I misunderstanding what both commands do or is something else going wrong? Any help is appreciated. Thanks!