Skip to content

Commit 34551f5

Browse files
committed
Update main.py
1 parent 2683ac2 commit 34551f5

File tree

1 file changed

+15
-35
lines changed

1 file changed

+15
-35
lines changed

main.py

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
import pandas as pd
1111

12-
# Sectors
12+
# Sector names
1313
T_idx = ['Agriculture','Manufacturing']
1414

1515
# Transaction matrix
@@ -52,40 +52,30 @@
5252
L = np.linalg.inv(I - A)
5353

5454
# Total intensities
55-
F = np.dot(f,L)
55+
F_linverse = np.dot(f,L)
5656

5757
# Scale to final demand
58-
E = np.multiply(F,y)
58+
E_linverse = np.multiply(F_linverse,y)
5959

6060
# Turn NumPy Array into Pandas DataFrame with indexed rows and columns
61-
E = pd.DataFrame(
62-
E,
61+
E_linverse = pd.DataFrame(
62+
E_linverse,
6363
index = T_idx,
6464
columns = T_idx
6565
)
6666

67-
# Production-based inventory
68-
E_production_based = (
69-
E.sum(axis=1) # Rows/Outputs/Production
70-
)
71-
72-
# Consumption-based inventory
73-
E_consumption_based = (
74-
E.sum(axis=0) # Columns/Inputs/Consumption
75-
)
76-
7767
print('\n>>> Leontief inverse-based results:')
7868
print('\nProduction-based-inventory:')
79-
print(E_production_based)
69+
print(E_linverse.sum(axis=1))
8070
print('\nConsumption-based-inventory:')
81-
print(E_consumption_based)
71+
print(E_linverse.sum(axis=0))
8272

8373
# =============================================================================
8474
# Series expansion-based calculation approach (approximation)
8575
# =============================================================================
8676

8777
# Total intensities (first eleven production layers)
88-
F_Series = {
78+
L_decomposed = {
8979
'Zeroth production layer' : I,
9080
'First production layer' : np.linalg.matrix_power(A, 1),
9181
'Second production layer' : np.linalg.matrix_power(A, 2),
@@ -99,32 +89,22 @@
9989
'Tenth production layer' : np.linalg.matrix_power(A,10),
10090
}
10191

102-
# sum(F_Series.values()) is an approxiamtion of L
92+
# sum(L_decomposed.values()) is an approxiamtion of L
10393
# Multiplication with f returns F
104-
F = np.dot(f,sum(F_Series.values()))
94+
F_series = np.dot(f,sum(L_decomposed.values()))
10595

10696
# Scale to final demand
107-
E = np.multiply(F,y)
97+
E_series = np.multiply(F_series,y)
10898

10999
# Turn NumPy Array into Pandas DataFrame with indexed rows and columns
110-
E = pd.DataFrame(
111-
E,
100+
E_series = pd.DataFrame(
101+
E_series,
112102
index = T_idx,
113103
columns = T_idx
114104
)
115105

116-
# Production-based inventory
117-
E_production_based = (
118-
E.sum(axis=1) # Rows/Outputs/Production
119-
)
120-
121-
# Consumption-based inventory
122-
E_consumption_based = (
123-
E.sum(axis=0) # Columns/Inputs/Consumption
124-
)
125-
126106
print('\n>>> Series expansion-based results:')
127107
print('\nProduction-based-inventory:')
128-
print(E_production_based)
108+
print(E_series.sum(axis=1))
129109
print('\nConsumption-based-inventory:')
130-
print(E_consumption_based)
110+
print(E_series.sum(axis=0))

0 commit comments

Comments
 (0)