Loading [MathJax]/jax/output/HTML-CSS/jax.js
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

42.3: Review of Python Numpy Package

( \newcommand{\kernel}{\mathrm{null}\,}\)

Direct Link to the Youtube video.

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

from IPython.display import YouTubeVideo
YouTubeVideo("_hbWtNgstlI",width=640,height=320, cc_load_policy=True)
from IPython.display import YouTubeVideo
YouTubeVideo("_hbWtNgstlI",width=640,height=320, cc_load_policy=True)

The Python Numpy library has a “Matrix” object which can be initialized as follows:

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

import numpy as np
A = np.matrix([[1,1], [20,25]])
b = np.matrix([[30],[690]])
print("A="+str(A))
print("b="+str(b))
import numpy as np
A = np.matrix([[1,1], [20,25]])
b = np.matrix([[30],[690]])
print("A="+str(A))
print("b="+str(b))
A=[[ 1  1]
 [20 25]]
b=[[ 30]
 [690]]

Python can solve equations in the Ax=b format with the numpy.linalg library. For example:

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

import numpy as sp

x = sp.linalg.solve(A, b)
print("X="+str(x))
import numpy as sp

x = sp.linalg.solve(A, b)
print("X="+str(x))
X=[[12.]
 [18.]]

The numpy.linalg library is just a subset of the scipy.linalg library. Oddly you can’t load the SciPy library the same way. Instead you can call it as follows:

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

import scipy.linalg as la

x = la.solve(A, b)
print("X="+str(x))
import scipy.linalg as la

x = la.solve(A, b)
print("X="+str(x))
X=[[12.]
 [18.]]
Do This

Convert the following system of linear equations to numpy matrices and solve using a python linear algebra solver 18x+21y=22672x3y=644

Login with LibreOne to run this code cell interactively.

If you have already signed in, please refresh the page.

##Put your answer to the above question here.
##Put your answer to the above question here.

This page titled 42.3: Review of Python Numpy Package is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Dirk Colbry via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?