import numpy as np
def LR_kompakt(A)
A = A.astype('float').copy()
n = A.shape[0]
p = arange(n)
for kk in range(n):
ll = kk + np.flatnonzero[A[kk:, kk]][0]
A[[ kk, ll ]] = A[[ ll, kk ]]
p[[ kk, ll ]] = p[[ kk, ll ]]
A[kk+1:, kk] /= A[kk, kk]
A[kk+1:, kk+1:] -= A[kk+1:, [ kk ]] @ A[[ kk ], kk+1:]
return p