Python-3.4.3/C3/Advanced-Matrix-Operations/English-timed

From Script | Spoken-Tutorial
Revision as of 10:49, 11 June 2019 by PoojaMoolya (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time
Narration
00:01 Welcome to the spoken tutorial on Advanced matrix operations.
00:07 In this tutorial, you will learn to, find Frobenius and infinity norm of a matrix
00:14 Find singular value decomposition of a matrix.
00:19 To record this tutorial, I am using Ubuntu Linux 16.04 operating system
00:26 Python 3.4.3 and IPython 5.1.0
00:33 To practise this tutorial, you should know about

Lists, arrays and accessing parts of arrays and performing basic matrix operations

00:46 If not, see the relevant Python tutorials on this website.
00:51 First we will see about flatten function.
00:55 flatten() function returns a copy of the array, collapsed into one dimension.
01:01 It can be used to convert a multidimensional matrix into a single dimension matrix
01:08 Let us start ipython.

Open the terminal.

01:13 Type, ipython3 and press Enter.

From here onwards, remember to press the Enter key after typing every command on the terminal.

01:25 Now let us see how to create arrays
01:29 Type from numpy import asmatrix comma arange
01:35 a is equal to asmatrix inside brackets arange inside brackets 1 comma 10 dot reshape inside brackets 3 comma 3
01:48 Then type, a

Now type, a dot flatten open and close brackets

01:57 First we imported arange function from numpy module.
02:02 Here, we can see 3 by 3 matrix is converted into one dimensional matrix.
02:08 Next we will see about frobenius norm.
02:12 It is defined as the square root of the sum of the absolute squares of its elements.
02:18 Pause the video.

Try this exercise and then resume the video.

02:24 Find out the frobenius norm of the inverse of the given 4 by 4 matrix.
02:30 Switch back to the terminal for the solution.
02:34 Type

m is equal to asmatrix inside brackets arange inside brackets 1 comma 17 dot reshape inside brackets 4 comma 4

02:46 Here, we have used asmatrix, arange and reshape functions.
02:52 We created a matrix of size 4 by 4 containing elements from 1 to 16.
02:59 Now type,

m inside square brackets 0 comma 1 is equal to 0

03:06 m inside square brackets 1 comma 3 is equal to 0
03:12 Then type, m

We changed the value of element at row 0 column 1 and row 1 column 3 to 0.

03:23 In order to find out the Frobenius norm of the inverse of matrix m, type as shown.
03:33 norm function is available in numpy.linalg module.
03:39 Next, we will see about infinity norm of a matrix.
03:44 It is defined as the maximum value of sum of the absolute value of elements in each row.
03:51 Pause the video.

Try this exercise and then resume the video.

03:57 Find the infinity norm of the matrix im.
04:01 Switch back to the terminal for the solution.
04:05 To find out the Infinity norm of the matrix im, type as shown.
04:11 Here value for ord parameter is passed as inf to calculate infinity norm.
04:18 To know more about norms type norm question mark
04:24 Press q to exit.
04:28 Next we will see about singular value decomposition.
04:33 In linear algebra, the singular value decomposition is factorization of real or complex matrix.
04:42 The SVD of matrix m1 can be found using svd function available in the numpy.linalg module.
04:52 Type as shown.
04:56 svd returns a tuple of 3 elements.
05:00 We have unpacked these values into variable U, sigma and V underscore conjugate.
05:08 Type, Capital U
05:12 Type, sigma
05:15 Type, Capital V underscore conjugate
05:20 We can validate the singular value decomposition by comparing the product of:

U, sigma and V underscore conjugate with m1

05:30 sigma is a one dimensional array which contains only the diagonal elements of the matrix.
05:37 Type as shown.

We first convert this array to a matrix.

05:43 Type smat

smat is a 2 by 3 zero matrix

05:51 Now type, smat inside square brackets colon 2 comma colon 2 is equal to diag inside brackets sigma
06:02 Then type smat
06:06 This replaces values at row 0 column 0 and row 1 column 1 in smat with values from sigma.
06:16 smat is a 2 by 3 matrix created for multiplications by placing values of sigma as diagonal elements and zero elsewhere.
06:27 Type as shown.
06:33 It returns True.

It means elements in m1 and in product of U, sigma and V underscore conjugate are equal.

06:43 This brings us to the end of this tutorial. Let us summarize.
06:49 In this tutorial, we have learnt to, Calculate the norm of a matrix using the function norm()
06:56 Calculate SVD of a matrix using the function svd()
07:01 Here is a self assessment question for you to solve

norm inside brackets A comma ord is equal to inside single quotes fro is same as norm inside brackets A

True or False.

07:19 And the answer is True, since the order is equal to inside single quotes fro stands for Frobenius norm.
07:29 Please post your timed queries in this forum.
07:33 Please post your general queries on Python in this forum.
07:37 FOSSEE team coordinates the TBC project.
07:41 Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India.

For more details, visit this website.

07:50 This is Priya from IIT Bombay signing off.

Thanks for watching.

Contributors and Content Editors

PoojaMoolya