Difference between revisions of "Python-3.4.3/C3/Advanced-Matrix-Operations/English"
Nancyvarkey (Talk | contribs) |
|||
(One intermediate revision by the same user not shown) | |||
Line 18: | Line 18: | ||
Objectives | Objectives | ||
− | |||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| In this tutorial, you will learn to, | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| In this tutorial, you will learn to, | ||
− | * find''' Frobenius''' and '''infinity | + | * find''' Frobenius''' and '''infinity norm''' of a '''matrix''' |
* find '''singular value decomposition''' of a '''matrix'''. | * find '''singular value decomposition''' of a '''matrix'''. | ||
− | |||
− | |||
|- | |- | ||
Line 37: | Line 34: | ||
* '''Python 3.4.3 '''and | * '''Python 3.4.3 '''and | ||
* '''IPython 5.1.0''' | * '''IPython 5.1.0''' | ||
− | |||
− | |||
|- | |- | ||
Line 44: | Line 39: | ||
Pre-requisites | Pre-requisites | ||
− | |||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| To practise this tutorial, you should know about | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| To practise this tutorial, you should know about | ||
− | * '''Lists, arrays '''and ''' | + | * '''Lists, arrays '''and accessing parts of '''arrays '''and |
− | * performing | + | * performing basic''' matrix operations''' |
− | If not, see the relevant Python tutorials on this website. | + | If not, see the relevant '''Python''' tutorials on this website. |
|- | |- | ||
Line 61: | Line 55: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| First we will see about '''flatten''' function. | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| First we will see about '''flatten''' function. | ||
− | * '''flatten() ''' | + | * '''flatten() function''' returns a copy of the '''array''', collapsed into one '''dimension'''. |
− | + | * It can be used to convert a '''multidimensional matrix''' into a '''single dimension matrix''' | |
− | + | ||
− | + | ||
|- | |- | ||
Line 80: | Line 72: | ||
− | From here onwards remember to press the Enter key after typing every command on the terminal. | + | From here onwards, remember to press the '''Enter''' key after typing every '''command''' on the '''terminal'''. |
|- | |- | ||
Line 89: | Line 81: | ||
'''a = asmatrix(arange(1,10).reshape(3,3))''' | '''a = asmatrix(arange(1,10).reshape(3,3))''' | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Now let us see how to create '''arrays''' | ||
− | ''' | + | Type '''from numpy import asmatrix,arange''' |
− | '''a | + | '''a''''' is equal to''''' asmatrix '''''inside brackets''''' arange '''''inside brackets '''''1''''' comma '''''10''''' dot '''''reshape '''''inside brackets '''''3 '''''comma '''''3''' |
+ | |- | ||
+ | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type '''a''' | ||
− | |||
+ | '''a.flatten()''' | ||
− | |||
− | |||
− | + | Highlight '''numpy import asmatrix,arange''' | |
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Then type, '''a''' | |
− | + | ||
− | ''' | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | Then type, '''a''' | + | |
Line 118: | Line 103: | ||
− | First we imported''' arange''' | + | First we imported''' arange function''' from '''numpy module'''. |
− | + | |- | |
− | Here, we can see '''3 by 3''' | + | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Highlight '''(arange(1,10).reshape(3,3))''' |
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Here, we can see '''3 by 3 matrix''' is converted into one '''dimensional matrix'''. | ||
|- | |- | ||
Line 129: | Line 115: | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Next we will see about '''frobenius norm.''' | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Next we will see about '''frobenius norm.''' | ||
− | + | It is defined as the '''square root''' of the sum of the '''absolute squares''' of its '''elements'''. | |
− | + | ||
− | + | ||
|- | |- | ||
Line 144: | Line 128: | ||
Assignment 1: '''Frobenius''' '''norm''' | Assignment 1: '''Frobenius''' '''norm''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Find out the ''' | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Find out the '''frobenius norm''' of the '''inverse''' of the given '''4 by 4 matrix'''. |
|- | |- | ||
| style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Switch to terminal | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Switch to terminal | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Switch back to the terminal for the solution. | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Switch back to the '''terminal''' for the solution. |
|- | |- | ||
Line 156: | Line 140: | ||
− | Highlight asmatrix(arange(1,17).reshape(4,4)) | + | Highlight '''asmatrix(arange(1,17).reshape(4,4))''' |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type | ||
Line 175: | Line 147: | ||
− | Here, we have used '''asmatrix, arange''' and '''reshape''' | + | Here, we have used '''asmatrix, arange''' and '''reshape functions'''. |
− | We created a matrix of size 4 by 4 containing elements from 1 to 16. | + | We created a '''matrix''' of size '''4 by 4''' containing '''elements''' from 1 to 16. |
+ | |- | ||
+ | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type, | ||
− | Now type, | + | '''<nowiki>m[0,1] = 0</nowiki>''' |
+ | |||
+ | '''<nowiki>m[1,</nowiki>3] =0''' | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Now type, | ||
'''m '''''inside square brackets '''''0 '''''comma '''''1''''' is equal to''''' 0''' | '''m '''''inside square brackets '''''0 '''''comma '''''1''''' is equal to''''' 0''' | ||
Line 187: | Line 164: | ||
'''m '''''inside square brackets '''''1''''' comma '''''3 '''''is equal to''''' 0''' | '''m '''''inside square brackets '''''1''''' comma '''''3 '''''is equal to''''' 0''' | ||
− | + | |- | |
− | Then type, '''m''' | + | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type '''m''' |
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Then type, '''m''' | ||
− | We changed the value of element at row 0 column 1 and row 1 column 3 to 0. | + | We changed the value of '''element''' at row 0 column 1 and row 1 column 3 to 0. |
|- | |- | ||
Line 203: | Line 181: | ||
− | Highlight numpy.linalg import inv, norm | + | Highlight '''numpy.linalg import inv, norm''' |
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| In order to find out the '''Frobenius | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| In order to find out the '''Frobenius norm''' of the '''inverse''' of '''matrix m''', type as shown. |
− | '''norm''' | + | '''norm function''' is available in''' numpy.linalg module.''' |
|- | |- | ||
Line 213: | Line 191: | ||
'''Infinity norm''' | '''Infinity norm''' | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Next, we will see about | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Next, we will see about '''infinity norm''' of a '''matrix.''' |
− | It is defined as the maximum value of sum of the '''absolute''' | + | It is defined as the maximum value of sum of the '''absolute value''' of '''elements''' in each row. |
|- | |- | ||
Line 227: | Line 205: | ||
|- | |- | ||
| style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Slide Assignment 2: Infinity norm | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Slide Assignment 2: Infinity norm | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Find the infinity norm of the | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Find the '''infinity norm''' of the '''matrix im.''' |
|- | |- | ||
| style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Switch to terminal | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Switch to terminal | ||
− | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Switch back to the terminal for the solution. | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Switch back to the '''terminal''' for the solution. |
|- | |- | ||
Line 237: | Line 215: | ||
'''from numpy import infnorm(im,ord=inf)''' | '''from numpy import infnorm(im,ord=inf)''' | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| To find out the '''Infinity norm''' of the '''matrix im''', type as shown. | ||
− | + | Here value for '''ord parameter''' is passed as '''inf''' to calculate '''infinity norm'''. | |
− | + | ||
− | + | ||
− | + | ||
− | Here value for '''ord''' | + | |
|- | |- | ||
Line 259: | Line 234: | ||
− | In | + | In '''linear algebra''', the '''singular value decomposition''' is factorization of '''real''' or '''complex matrix.''' |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 278: | Line 248: | ||
− | |||
− | ''' | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| The '''SVD''' of '''matrix m1''' can be found using '''svd function''' available in the '''numpy.linalg module'''. |
− | |||
− | + | Type as shown. | |
− | + | ||
+ | '''svd''' returns a '''tuple''' of 3 '''elements'''. | ||
− | |||
+ | We have unpacked these values into '''variable U, sigma''' and '''V''''' underscore '''''conjugate.''' | ||
− | + | |- | |
+ | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type, | ||
+ | '''U''' | ||
− | + | '''sigma''' | |
+ | '''V_conjugate''' | ||
− | Type, Capital '''U''' | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type, Capital '''U''' |
Line 304: | Line 275: | ||
Type, Capital '''V''''' underscore '''''conjugate''' | Type, Capital '''V''''' underscore '''''conjugate''' | ||
+ | |- | ||
+ | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Narration only | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| We can validate the '''singular value decomposition''' by comparing the product of: | ||
+ | |||
+ | '''U, sigma''' and '''V '''''underscore '''''conjugate '''with''' m1''' | ||
+ | |||
+ | |||
+ | '''sigma''' is a one '''dimensional array''' which contains only the '''diagonal elements''' of the '''matrix'''. | ||
|- | |- | ||
Line 313: | Line 292: | ||
'''smat = zeros((2,3))''' | '''smat = zeros((2,3))''' | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type as shown. | ||
− | ''' | + | We first convert this '''array''' to a '''matrix'''. |
− | + | ||
− | + | ||
− | ''' | + | |
− | + | ||
− | + | ||
− | + | ||
+ | |- | ||
+ | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type, | ||
'''smat''' | '''smat''' | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type '''smat''' | ||
− | + | '''smat''' is a 2 by 3 '''zero matrix''' | |
− | + | ||
− | ''' | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | ''' | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | ''' | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | |- | ||
+ | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type, | ||
+ | '''<nowiki>smat[:2, :2] = diag(sigma)</nowiki>''' | ||
+ | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Now type, | ||
'''smat''''' inside square brackets colon '''''2 '''''comma''''' '''''colon '''''2 '''''is equal to''''' diag '''''inside brackets '''''sigma''' | '''smat''''' inside square brackets colon '''''2 '''''comma''''' '''''colon '''''2 '''''is equal to''''' diag '''''inside brackets '''''sigma''' | ||
+ | |- | ||
+ | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type '''smat''' | ||
− | Then type | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Then type '''smat''' |
− | + | ||
− | '''smat''' | + | |
This replaces values at row 0 column 0 and row 1 column 1 in '''smat '''with values from '''sigma. ''' | This replaces values at row 0 column 0 and row 1 column 1 in '''smat '''with values from '''sigma. ''' | ||
− | + | |- | |
− | '''smat''' | + | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type |
− | + | '''allclose(m1, U * smat * V_conjugate)''' | |
− | + | | style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Type as shown. | |
− | Type as shown. | + | |
Line 376: | Line 328: | ||
− | It means elements in '''m1''' and in product of''' U, sigma '''and''' V''''' underscore '''''conjugate '''are equal. | + | It means '''elements''' in '''m1''' and in product of''' U, sigma '''and''' V''''' underscore '''''conjugate '''are equal. |
|- | |- | ||
Line 390: | Line 342: | ||
In this tutorial, we have learnt to, | In this tutorial, we have learnt to, | ||
− | * Calculate the '''norm''' of a '''matrix''' using the | + | * Calculate the '''norm''' of a '''matrix''' using the '''function norm()''' |
− | * Calculate '''SVD''' of a '''matrix''' using the '''function | + | * Calculate '''SVD''' of a '''matrix''' using the '''function svd()''' |
− | + | ||
− | + | ||
|- | |- | ||
| style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Show Slide | | style="background-color:#ffffff;border-top:0.5pt solid #000001;border-bottom:0.5pt solid #000001;border-left:0.5pt solid #000001;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;"| Show Slide | ||
− | Self assessment questions slide | + | Self assessment questions slide. |
Line 406: | Line 356: | ||
1. '''norm''''' inside brackets '''''A '''''comma '''''ord''''' is equal to inside single quotes '''''fro''' is the same as '''norm '''''inside brackets '''''A''' | 1. '''norm''''' inside brackets '''''A '''''comma '''''ord''''' is equal to inside single quotes '''''fro''' is the same as '''norm '''''inside brackets '''''A''' | ||
− | True or False | + | True or False. |
|- | |- |
Latest revision as of 18:37, 7 December 2018
Title of script: Advanced Matrix Operations
Author: Puneeth, Thirumalesh H S, Arun KP
Keywords: Python, IPython, array, matrices, norm, svd, video tutorial
|
|
Show Slide title | Welcome to the spoken tutorial on Advanced matrix operations. |
Show Slide
Objectives
|
In this tutorial, you will learn to,
|
Show Slide
System Specifications |
To record this tutorial, I am using
|
Show Slide
Pre-requisites
|
To practise this tutorial, you should know about
If not, see the relevant Python tutorials on this website. |
Show Slide
|
First we will see about flatten function.
|
Open terminal | Let us start ipython.
|
Type,
ipython3 |
Type, ipython3 and press Enter.
|
Type,
from numpy import asmatrix,arange
|
Now let us see how to create arrays
|
Type a
|
Then type, a
|
Highlight (arange(1,10).reshape(3,3)) | Here, we can see 3 by 3 matrix is converted into one dimensional matrix. |
Show Slide
Frobenius norm of a matrix |
Next we will see about frobenius norm.
It is defined as the square root of the sum of the absolute squares of its elements. |
Pause the video.
| |
Show Slide
Assignment 1: Frobenius norm |
Find out the frobenius norm of the inverse of the given 4 by 4 matrix. |
Switch to terminal | Switch back to the terminal for the solution. |
Type,
m = asmatrix(arange(1,17).reshape(4,4))
|
Type
m is equal to asmatrix inside brackets arange inside brackets 1 comma 17 dot reshape inside brackets 4 comma 4
|
Type,
m[0,1] = 0 m[1,3] =0 |
Now type,
m inside square brackets 0 comma 1 is equal to 0 m inside square brackets 1 comma 3 is equal to 0 |
Type m | Then type, m
|
Type,
from numpy.linalg import inv, norm im = inv(m) norm(im)
|
In order to find out the Frobenius norm of the inverse of matrix m, type as shown.
|
Show Slide
Infinity norm |
Next, we will see about infinity norm of a matrix.
|
Pause the video.
| |
Slide Assignment 2: Infinity norm | Find the infinity norm of the matrix im. |
Switch to terminal | Switch back to the terminal for the solution. |
Type,
from numpy import infnorm(im,ord=inf) |
To find out the Infinity norm of the matrix im, type as shown.
|
Type, norm? | To know more about norms type norm question mark
|
Show Slide
Singular value decomposition |
Next we will see about singular value decomposition.
|
Type,
from numpy import matrix from numpy.linalg import svd m1 = matrix([[3,2,2],[2,3,-2]]) U,sigma,V_conjugate = svd(m1)
|
The SVD of matrix m1 can be found using svd function available in the numpy.linalg module.
svd returns a tuple of 3 elements.
|
Type,
U sigma V_conjugate |
Type, Capital U
|
Narration only | We can validate the singular value decomposition by comparing the product of:
U, sigma and V underscore conjugate with m1
|
Type,
from numpy import diag,allclose from numpy.matlib import zeros smat = zeros((2,3)) |
Type as shown.
|
Type,
smat |
Type smat
|
Type,
smat[:2, :2] = diag(sigma) |
Now type,
smat inside square brackets colon 2 comma colon 2 is equal to diag inside brackets sigma |
Type smat | Then type smat
|
Type
allclose(m1, U * smat * V_conjugate) |
Type as shown.
|
Show Slide
Summary
|
This brings us to the end of this tutorial. Let us summarize.
|
Show Slide
Self assessment questions slide.
|
Here is a self assessment question for you to solve
1. norm inside brackets A comma ord is equal to inside single quotes fro is the same as norm inside brackets A True or False. |
Show Slide
Solution of self assessment questions on slide |
And the answer is True since the order is equal to inside single quotes fro stands for Frobenius norm. |
Show Slide Forum | Please post your timed queries in this forum. |
Show Slide Fossee Forum | Please post your general queries on Python in this forum. |
Slide TBC | FOSSEE team coordinates the TBC project. |
Show Slide
Acknowledgment |
Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India.
For more details, visit this website. |
Previous slide | This is Priya from IIT Bombay signing off.
Thanks for watching. |