Refactoring for More Pythonic Code

This commit is contained in:
2022-12-06 21:27:56 -03:00
parent 4b863c0ad8
commit 1d62ac70df
6 changed files with 102 additions and 72 deletions

View File

@@ -9,6 +9,7 @@ pandas = "*"
cython = "*"
[dev-packages]
coverage = "*"
[requires]
python_version = "3.10"

61
Pipfile.lock generated
View File

@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "79ddb27bf6f5e6aedfbf302b825eef67f73de68547f8081fc3a5eda70ce19d6d"
"sha256": "05244cb1f31b353649158a164e637872ff2c8db06a22b2c25e1275572ca58092"
},
"pipfile-spec": 6,
"requires": {
@@ -153,5 +153,62 @@
"version": "==1.16.0"
}
},
"develop": {}
"develop": {
"coverage": {
"hashes": [
"sha256:027018943386e7b942fa832372ebc120155fd970837489896099f5cfa2890f79",
"sha256:11b990d520ea75e7ee8dcab5bc908072aaada194a794db9f6d7d5cfd19661e5a",
"sha256:12adf310e4aafddc58afdb04d686795f33f4d7a6fa67a7a9d4ce7d6ae24d949f",
"sha256:1431986dac3923c5945271f169f59c45b8802a114c8f548d611f2015133df77a",
"sha256:1ef221513e6f68b69ee9e159506d583d31aa3567e0ae84eaad9d6ec1107dddaa",
"sha256:20c8ac5386253717e5ccc827caad43ed66fea0efe255727b1053a8154d952398",
"sha256:2198ea6fc548de52adc826f62cb18554caedfb1d26548c1b7c88d8f7faa8f6ba",
"sha256:255758a1e3b61db372ec2736c8e2a1fdfaf563977eedbdf131de003ca5779b7d",
"sha256:265de0fa6778d07de30bcf4d9dc471c3dc4314a23a3c6603d356a3c9abc2dfcf",
"sha256:33a7da4376d5977fbf0a8ed91c4dffaaa8dbf0ddbf4c8eea500a2486d8bc4d7b",
"sha256:42eafe6778551cf006a7c43153af1211c3aaab658d4d66fa5fcc021613d02518",
"sha256:4433b90fae13f86fafff0b326453dd42fc9a639a0d9e4eec4d366436d1a41b6d",
"sha256:4a5375e28c5191ac38cca59b38edd33ef4cc914732c916f2929029b4bfb50795",
"sha256:4a8dbc1f0fbb2ae3de73eb0bdbb914180c7abfbf258e90b311dcd4f585d44bd2",
"sha256:59f53f1dc5b656cafb1badd0feb428c1e7bc19b867479ff72f7a9dd9b479f10e",
"sha256:5dbec3b9095749390c09ab7c89d314727f18800060d8d24e87f01fb9cfb40b32",
"sha256:633713d70ad6bfc49b34ead4060531658dc6dfc9b3eb7d8a716d5873377ab745",
"sha256:6b07130585d54fe8dff3d97b93b0e20290de974dc8177c320aeaf23459219c0b",
"sha256:6c4459b3de97b75e3bd6b7d4b7f0db13f17f504f3d13e2a7c623786289dd670e",
"sha256:6d4817234349a80dbf03640cec6109cd90cba068330703fa65ddf56b60223a6d",
"sha256:723e8130d4ecc8f56e9a611e73b31219595baa3bb252d539206f7bbbab6ffc1f",
"sha256:784f53ebc9f3fd0e2a3f6a78b2be1bd1f5575d7863e10c6e12504f240fd06660",
"sha256:7b6be138d61e458e18d8e6ddcddd36dd96215edfe5f1168de0b1b32635839b62",
"sha256:7ccf362abd726b0410bf8911c31fbf97f09f8f1061f8c1cf03dfc4b6372848f6",
"sha256:83516205e254a0cb77d2d7bb3632ee019d93d9f4005de31dca0a8c3667d5bc04",
"sha256:851cf4ff24062c6aec510a454b2584f6e998cada52d4cb58c5e233d07172e50c",
"sha256:8f830ed581b45b82451a40faabb89c84e1a998124ee4212d440e9c6cf70083e5",
"sha256:94e2565443291bd778421856bc975d351738963071e9b8839ca1fc08b42d4bef",
"sha256:95203854f974e07af96358c0b261f1048d8e1083f2de9b1c565e1be4a3a48cfc",
"sha256:97117225cdd992a9c2a5515db1f66b59db634f59d0679ca1fa3fe8da32749cae",
"sha256:98e8a10b7a314f454d9eff4216a9a94d143a7ee65018dd12442e898ee2310578",
"sha256:a1170fa54185845505fbfa672f1c1ab175446c887cce8212c44149581cf2d466",
"sha256:a6b7d95969b8845250586f269e81e5dfdd8ff828ddeb8567a4a2eaa7313460c4",
"sha256:a8fb6cf131ac4070c9c5a3e21de0f7dc5a0fbe8bc77c9456ced896c12fcdad91",
"sha256:af4fffaffc4067232253715065e30c5a7ec6faac36f8fc8d6f64263b15f74db0",
"sha256:b4a5be1748d538a710f87542f22c2cad22f80545a847ad91ce45e77417293eb4",
"sha256:b5604380f3415ba69de87a289a2b56687faa4fe04dbee0754bfcae433489316b",
"sha256:b9023e237f4c02ff739581ef35969c3739445fb059b060ca51771e69101efffe",
"sha256:bc8ef5e043a2af066fa8cbfc6e708d58017024dc4345a1f9757b329a249f041b",
"sha256:c4ed2820d919351f4167e52425e096af41bfabacb1857186c1ea32ff9983ed75",
"sha256:cca4435eebea7962a52bdb216dec27215d0df64cf27fc1dd538415f5d2b9da6b",
"sha256:d900bb429fdfd7f511f868cedd03a6bbb142f3f9118c09b99ef8dc9bf9643c3c",
"sha256:d9ecf0829c6a62b9b573c7bb6d4dcd6ba8b6f80be9ba4fc7ed50bf4ac9aecd72",
"sha256:dbdb91cd8c048c2b09eb17713b0c12a54fbd587d79adcebad543bc0cd9a3410b",
"sha256:de3001a203182842a4630e7b8d1a2c7c07ec1b45d3084a83d5d227a3806f530f",
"sha256:e07f4a4a9b41583d6eabec04f8b68076ab3cd44c20bd29332c6572dda36f372e",
"sha256:ef8674b0ee8cc11e2d574e3e2998aea5df5ab242e012286824ea3c6970580e53",
"sha256:f4f05d88d9a80ad3cac6244d36dd89a3c00abc16371769f1340101d3cb899fc3",
"sha256:f642e90754ee3e06b0e7e51bce3379590e76b7f76b708e1a71ff043f87025c84",
"sha256:fc2af30ed0d5ae0b1abdb4ebdce598eafd5b35397d4d75deb341a614d333d987"
],
"index": "pypi",
"version": "==6.5.0"
}
}
}

View File

@@ -19,23 +19,21 @@
import numpy as np
def eigen(a: np.ndarray) -> np.ndarray:
k = 0
def eigen(a: np.ndarray) -> np.ndarray:
l = np.ones((a.shape[0]))
at = a # variavel temporaria para A
b = np.random.rand(a.shape[0], a.shape[1])
while (k < at.shape[0]):
for k in range(at.shape[0]):
u = np.random.rand(at.shape[0], 1)
u = u / max(u.min(), u.max(), key=abs)
ctrl = 0
while (ctrl != l[k]):
while ctrl != l[k]:
ctrl = l[k]
u = at.dot(u)
l[k] = max(u.min(), u.max(), key=abs)
@@ -55,10 +53,9 @@ def eigen(a: np.ndarray) -> np.ndarray:
i = 0
while (u[i] == 0):
while u[i] == 0:
i += 1
at = at - (1 / u[i]) * u * at[i]
k += 1
return l, b

View File

@@ -19,30 +19,19 @@
import numpy as np
def matrix(matrix: np.ndarray) -> np.ndarray:
i = 0
def matrix(a: np.ndarray) -> np.ndarray:
while (i < matrix.shape[0]):
for i in range(a.shape[0]):
for j in range(a.shape[1]):
a[i][j] = float(input(f"Insert the element a{i+1}x{j+1}: "))
j = 0
return a
while (j < matrix.shape[1]):
matrix[i][j] = float(input('Insira o elemento {}x{}: '.format((i+1),(j+1))))
j += 1
def vector(v: np.ndarray) -> np.ndarray:
i += 1
for j in range(v.shape[0]):
v[j] = float(input(f"Insert the element b{j+1}: "))
return matrix
def vector(vector: np.ndarray) -> np.ndarray:
j=0
while (j < vector.shape[0]):
vector[j] = float(input('Insira o elemento b{}: '.format((j+1))))
j += 1
return vector
return v

View File

@@ -20,26 +20,13 @@
import numpy as np
import pandas as pd
def numpy(path:str, sep: str = None, decimal: str = None) -> np.ndarray:
if sep is None:
sep = ","
if decimal is None:
decimal = "."
def numpy(path: str, sep: str = ",", decimal: str = ".") -> np.ndarray:
df = pd.read_csv(path, sep=sep, decimal=decimal, header=None)
array = df.to_numpy()
return array
def pandas(path: str, sep: str = None, decimal: str = None) -> pd.DataFrame:
if sep is None:
sep = ","
if decimal is None:
decimal = "."
def pandas(path: str, sep: str = ",", decimal: str = ".") -> pd.DataFrame:
return pd.read_csv(path, sep=sep, decimal=decimal)

View File

@@ -21,15 +21,14 @@ import pandas as pd
import numpy as np
import csv
def numpy(array: np.ndarray, path: str) -> np.ndarray:
with open(path, mode='w') as sistema_linear:
solution_writer = csv.writer(sistema_linear, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
with open(path, mode='w') as linear_system:
solution_writer = csv.writer(linear_system, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
solution_writer.writerows(array)
return array
def pandas(df: pd.DataFrame, path:str) -> None:
def pandas(df: pd.DataFrame, path: str) -> None:
df.to_csv(path)