Path: blob/master/4_matrix_math/4_matrix_math.ipynb
1141 views
Kernel: Python 3
In [1]:
Calculate profit/loss from revenue and expenses
In [4]:
In [5]:
Out[5]:
array([[100, 110, 120],
[ 14, 20, 20],
[ 4, 8, 10]])
Calculate total sales from units and price per unit using matrix multiplication
In [6]:
In [7]:
Out[7]:
array([[30000, 16000, 60000],
[ 5000, 4000, 18000],
[ 2000, 2000, 8400]])
In above case numpy is using broadcasting so it expands price_per_unit array from 1 row, 3 columns to 3 row and 3 columns. Correct way to do matrix multiplication is to use dot product as shown below
In [8]:
Out[8]:
array([34400, 50000, 64400])