40 - Norm of matrix |
40 - Norm of matrix |
41 - Singular Value Decomposition of matrices |
41 - Singular Value Decomposition of matrices |
42 |
42 |
43 * Creating a matrix |
43 * Creating a matrix |
44 - Creating a matrix using direct data |
44 - Creating a matrix using direct data |
45 : In []: m1 = matrix([1, 2, 3, 4]) |
45 : In []: m1 = array([1, 2, 3, 4]) |
46 - Creating a matrix using lists |
46 - Creating a matrix using lists |
47 : In []: l1 = [[1,2,3,4],[5,6,7,8]] |
47 : In []: l1 = [[1,2,3,4],[5,6,7,8]] |
48 : In []: m2 = matrix(l1) |
48 : In []: m2 = array(l1) |
49 - A matrix is basically an array |
49 * Exercise 1 |
|
50 Create a (2, 4) matrix ~m3~ |
|
51 : m3 = [[5, 6, 7, 8], |
|
52 : [9, 10, 11, 12]] |
|
53 * Solution 1 |
|
54 - m3 can be created as, |
50 : In []: m3 = array([[5,6,7,8],[9,10,11,12]]) |
55 : In []: m3 = array([[5,6,7,8],[9,10,11,12]]) |
51 |
56 |
52 * Matrix operations |
57 * Matrix operations |
53 - Element-wise addition (both matrix should be of order ~mXn~) |
58 - Element-wise addition (both matrix should be of order ~mXn~) |
54 : In []: m3 + m2 |
59 : In []: m3 + m2 |
55 - Element-wise subtraction (both matrix should be of order ~mXn~) |
60 - Element-wise subtraction (both matrix should be of order ~mXn~) |
56 : In []: m3 - m2 |
61 : In []: m3 - m2 |
57 * Matrix Multiplication |
62 * Matrix Multiplication |
58 - Matrix Multiplication |
63 - Element-wise multiplication using ~m3 * m2~ |
59 : In []: m3 * m2 |
64 : In []: m3 * m2 |
|
65 - Matrix Multiplication using ~dot(m3, m2)~ |
|
66 : In []: dot(m3, m2) |
60 : Out []: ValueError: objects are not aligned |
67 : Out []: ValueError: objects are not aligned |
61 - Element-wise multiplication using ~multiply()~ |
|
62 : multiply(m3, m2) |
|
63 |
68 |
64 * Matrix Multiplication (cont'd) |
69 * Matrix Multiplication (cont'd) |
65 - Create two compatible matrices of order ~nXm~ and ~mXr~ |
70 - Create two compatible matrices of order ~nXm~ and ~mXr~ |
66 : In []: m1.shape |
71 : In []: m1.shape |
67 - matrix m1 is of order ~1 X 4~ |
72 - matrix m1 is of order ~1 X 4~ |
68 - Creating another matrix of order ~4 X 2~ |
73 - Creating another matrix of order ~4 X 2~ |
69 : In []: m4 = matrix([[1,2],[3,4],[5,6],[7,8]]) |
74 : In []: m4 = array([[1,2],[3,4],[5,6],[7,8]]) |
70 - Matrix multiplication |
75 - Matrix multiplication |
71 : In []: m1 * m4 |
76 : In []: dot(m1, m4) |
72 * Recall from ~array~ |
77 * Recall from ~array~ |
73 - The functions |
78 - The functions |
74 - ~identity(n)~ - |
79 - ~identity(n)~ - |
75 creates an identity matrix of order ~nXn~ |
80 creates an identity matrix of order ~nXn~ |
76 - ~zeros((m,n))~ - |
81 - ~zeros((m,n))~ - |