Created
April 10, 2019 18:12
-
-
Save jenncross/baf9b7397e651229a1da786d35a12034 to your computer and use it in GitHub Desktop.
matrix multiplication
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
""" | |
Created on Wed Apr 10 13:27:17 2019 | |
@author: jenncross | |
""" | |
import numpy as np | |
#Apples cost $3, oranges cost $4, grapes cost $2 | |
# .... Boston prices, am I right? | |
prices = np.array([[3], | |
[4], | |
[2]]) | |
#On monday we sell 13 apples, 8 oranges, 6 grapes? | |
#On tuesday we sell 9, 7, and 4 | |
#On wednesday 7, 4, 0 | |
#On thursday 15, 6, 3 | |
sales = np.array([[13, 8, 6], | |
[9, 7, 4], | |
[7, 4, 0], | |
[15, 6, 3]]) | |
#How much to we make each day? | |
income = np.matmul(sales, prices) | |
print(income) | |
#What if we wanted to make $100 monday, $75 tuesday, and $50 wednesday? | |
# This would be a system of equations. | |
# 13*a + 8*o + 6*g = 100 | |
# 9*a + 7*o + 4*g = 75 | |
# 7*a + 4*o + 0*g = 50 | |
# What are the prices a, o and g that make this work? | |
sales = np.array([[13, 8, 6], | |
[9, 7, 4], | |
[7, 4, 0]]) | |
goals = np.array([[100], | |
[75], | |
[50]]) | |
#We can solve this system of equations with numpy matrices .... | |
solution_prices = np.linalg.solve(sales, goals) | |
print(solution_prices) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment