-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathio.py
More file actions
31 lines (23 loc) · 661 Bytes
/
io.py
File metadata and controls
31 lines (23 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Solves matrix from file input"""
import sys
import solvers
import numpy as np
try:
fp = open('linsolver.in', 'r')
except FileNotFoundError:
print("Can not open file {}".format('linsolver.in'))
print('Exiting...')
sys.exit(1)
else:
data = np.loadtxt('linsolver.in', skiprows=1, dtype=float, delimiter=' ')
array = data[0:3]
vector = data[3]
# numstr = fp.readline(1)
# numval = int(numstr)
result = solvers.gaussian_eliminate(array, vector)
if result is None:
fp = open('linsolver.out', 'w')
fp.write('ERROR: LINDEP')
fp.close()
else:
np.savetxt('linsolver.out', result)