<jupyter_start><jupyter_text>Solution of a linear system  https://drive.google.com/file/d/1hBZ4tsoCt9P2v3SLft-Cn9_dhTQ9ULbz/view<jupyter_code>import sys
import re
import numpy as np
#import parser as ps
%ls -l
print()
%ls -l input/
# if len(sys.argv) > 1:
#     #print sys.argv[1]
#     f = open('input/'+sys.argv[1], 'r')
# else:
#     f = open('input.txt', 'r')

f = open('input.txt', 'r')
# pattern = re.compile(r'(?P<a>(-?\d+/))x(?P<b>([+-]\d+/))y(?P<c>([+-]\d+/))(\=)(?P<r>[0-9]+)')

pattern = re.compile(r'(?P<a>(-?\d+))x(?P<b>([+-]\d+))y(?P<c>([+-]\d+))(\=)(?P<r>[0-9]+)')
_ = """
matrixA = np.array([])
matrixB = np.array([])

for line in f:
    #line = f.readline()
    #newLine = ps.expr(line).compile()
    #match = pattern.match(line) #or findall
    match = re.search(pattern, line)#.groups()
    print match, type(match)
    print pattern, type(pattern)
    
    if match:
        a = int(match.group('a'))
        b = int(match.group('b'))
        c = int(match.group('c'))
        newRow = [a, b, c]
        matrixA = np.concatenate(matrixA, newRow)    
    
        r = int(match.group('r'))
        newRow = [r]
        matrixB = np.concatenate(matrixB, newRow)
    else:
        raise Exception('Pattern not matched')
"""
matrixA = np.array([[2, 3, 6], [0, 4, 2], [1, 3, 5]])
matrixB = np.array([[2], [3], [1]])

print('matrixA:\n %s\n' % matrixA)
print('matrixB:\n %s' % matrixB)
%%time
detA = np.linalg.det(matrixA)

if detA == 0:
    print('Determinant is 0. Program will stop')
    quit()

matrixAinv = np.linalg.inv(matrixA)
print('---', 'Inverse matrix is: ')
print(matrixAinv)
checkInv = np.allclose(np.dot(matrixA, matrixAinv), np.eye(3))

print("\nIs matrixAinv ok ?", checkInv)

#x = np.linalg.solve(a, b, c)

#Check that the solution is correct:
#np.allclose(np.dot(a, x), b)<jupyter_output>--- Inverse matrix is: 
[[ 1.4  0.3 -1.8]
 [ 0.2  0.4 -0.4]
 [-0.4 -0.3  0.8]]

Is matrixAinv ok ? True
{'fraction_non_alphanumeric': 0.23284823284823286, 'fraction_numerical': 0.02442827442827443, 'mean_word_length': 3.1847826086956523, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '507224', 'license': 'MIT', 'n_tokens_mistral': 857, 'n_tokens_neox': 831, 'n_words': 171, 'path': 'labs-neural-networks/hw-lab2/Refactor.ipynb', 'repo_name': 'xR86/ml-stuff', 'size': '1924'}