Merge branch 'future'

This commit is contained in:
2020-11-25 07:36:58 -03:00
10 changed files with 76 additions and 25 deletions

View File

@@ -44,8 +44,48 @@ def identity(matrix):
return matrix return matrix
def gauss(matrix): def gauss(a):
for i in range(a.shape[0]):
k = i + 1
while (k<a.shape[0]):
l = 1
while (a[i][i] == 0 and l < a.shape[0]):
temp = a[i].copy()
a[i] = a[i+l]
a[i+l] = temp
l += 1
if (a[k][i] == 0):
while (k < a.shape[0]):
k += 1
else:
a[k] = a[k] - (a[k][i]/a[i][i])*a[i]
k += 1
i += 1
x = np.zeros(a.shape[0])
for j in reversed(range(x.shape[0])):
suma = 0
for k in range (j,a.shape[0]):
suma += a[j][k]*x[k]
x[j] = (a[j][a.shape[0]] - suma)/a[j][j]
return x
def inverse(matrix):
matrix = np.hstack(matrix,np.identity(matrix.shape[0]))
i = 0 i = 0
k = 0 k = 0
@@ -65,7 +105,7 @@ def gauss(matrix):
while (k < matrix.shape[0]): while (k < matrix.shape[0]):
if (k == i) or (matrix[i][i] == 0): if (k == i) or (matrix[k][i] == 0) or (matrix[i][i] == 0):
k += 1 k += 1
@@ -87,10 +127,6 @@ def gauss(matrix):
return matrix[:,(matrix.shape[0]):] return matrix[:,(matrix.shape[0]):]
def inverse(matrix):
return gauss(np.hstack((matrix, identity(np.zeros(matrix.shape)))))
def cholesky(A, b): def cholesky(A, b):
g = np.zeros((A.shape)) g = np.zeros((A.shape))

View File

@@ -20,18 +20,12 @@
import numpy as np import numpy as np
import pandas as pd import pandas as pd
def numpy(path, sep=None, decimal=None): def numpy(path, sep=None):
if sep is None: if sep is None:
sep = "," sep = ","
if decimal is None: return np.genfromtxt(path, delimiter=sep)
decimal = "."
df=pd.read_csv(path, sep=sep, decimal=decimal, header=None)
array = df.to_numpy()
return array
def pandas(path, sep=None, decimal=None): def pandas(path, sep=None, decimal=None):

View File

@@ -17,5 +17,8 @@
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from .write import numpy as np from .write import numpy
from .write import pandas as pd from .write import pandas
np = numpy()
pd = pandas()

View File

@@ -18,16 +18,34 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import csv import csv
import numpy as np
import pandas as pd
def numpy(array, path): class numpy:
with open(path, mode='w') as sistema_linear: def __init__(self):
pass
def csv(self, array, path):
solution_writer = csv.writer(sistema_linear, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) with open(path, mode='w') as sistema_linear:
solution_writer.writerows(array)
return array
def pandas(df, path): solution_writer = csv.writer(sistema_linear, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
solution_writer.writerows(array)
df.to_csv(path)
def txt(self, array, path):
np.savetxt(path, array, fmt='%8f', delimiter=' ', \
newline='\n', header='', footer='', comments='# ', encoding=None)
class pandas:
def __init__(self):
pass
def csv(self, df, path):
df.to_csv(path)
def txt(self, df, path):
np.savetxt(path, df.values, fmt='%8f', delimiter=' ', \
newline='\n', header='', footer='', comments='# ', encoding=None)