Last active
May 21, 2020 18:00
-
-
Save velicanu/ed868c94eb93efda4f3c44997a5447c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
# Solves A . x = y by x = A_inverse . y | |
df = pd.read_csv( | |
"https://docs.google.com/spreadsheets/d/11gz4F5TUjQL0hRl4gBYQrtCJ3SRY_jwIW-H3HJqUyuE/gviz/tq?tqx=out:csv&sheet=Sheet1" | |
).replace({np.nan: 0}) | |
y_vector = df["TOTAL"].to_numpy() | |
A_df = df.drop(["TOTAL", "NAME"], axis=1) | |
A = A_df.to_numpy() | |
A_inverse = np.linalg.inv(A) | |
x_vector = A_inverse.dot(y_vector).reshape(1, len(y_vector)) | |
x_df = pd.DataFrame(data=x_vector, columns=A_df.columns) | |
x_df.to_csv(open("solution.csv", "w"), index=False) | |
print("Wrote output to solution.csv\n") | |
print(x_df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment