Copyright (C) 2020 Andreas Kloeckner
import numpy as np
np.random.seed(5)
n = 4
A = np.round(np.random.randn(n, n) * 5)
A
array([[ 2., -2., 12., -1.], [ 1., 8., -5., -3.], [ 1., -2., -6., -1.], [ -2., 3., -8., -4.]])
Now compute A1
to eliminate A[1,0]
:
A1 = A.copy()
A1[1] -= 1/2*A1[0]
A1
array([[ 2. , -2. , 12. , -1. ], [ 0. , 9. , -11. , -2.5], [ 1. , -2. , -6. , -1. ], [ -2. , 3. , -8. , -4. ]])
And A2
with A[2,0] == 0
:
A2 = A1.copy()
A2[2] -= 1/2*A[0]
A2
array([[ 2. , -2. , 12. , -1. ], [ 0. , 9. , -11. , -2.5], [ 0. , -1. , -12. , -0.5], [ -2. , 3. , -8. , -4. ]])