1 Hello and welcome to the tutorial on Matrices. |
1 Hello friends and welcome to this tutorial on Matrices. |
2 All matrices operations are done using arrays. |
2 In python all matrix operations are done using arrays. |
3 We have already seen in previous session that how arrays are better suited for particular mathematical operations. In this session we are going to cover more details on Arrays(matrices), how to create/initialize them, how to manipulate and use them for solving given problem. |
3 We have already seen in previous session that how arrays are better suited for certain mathematical operations. In this session we are going to cover more details on using Arrays as matrices, such as, how to create them, how to initialize them, how to manipulate and use them for solving given problem. |
4 |
4 |
5 First thing first, we start with creating a normal array by: |
5 First things first, let's start by creating a normal array, type: |
6 a (equal to)= array([5, 8, 10, 13]) |
6 a equal to array([5, 8, 10, 13]) |
7 |
7 |
8 and we have a as array, check the value by |
8 let's check the value of a by typing |
9 a |
9 a |
10 |
10 |
11 Here a is single dimension array, that is it has only one row. We can create multi-dimensional arrays by |
11 Here a is single dimension array, that is it has only one row. Let's now look at creating multi-dimensional arrays by |
12 |
12 |
13 c = array([[11,12,13], [21,22,23], [31,32,33]]) |
13 c = array([[11,12,13], [21,22,23], [31,32,33]]) |
14 |
14 |
15 both c and a are arrays but with different dimensions or shape |
15 both c and a are arrays but with different dimensions or shape |
16 we can check shape of arrays by using shape attribute of arrays. |
16 we can check shape of arrays by using shape attribute of arrays. |
17 a.shape |
17 a.shape |
18 c.shape |
18 c.shape |
19 |
19 |
20 some other handy array initialization methods are also available to make life easier. |
20 A few other handy array initialization methods are also available to make life easier. |
21 say we want to create an array of size 3x4 with all the values initialized to be 1, we can use |
21 say we want to create an array of size 3x4 with all the elements initialized to 1, we use |
22 b = ones((3, 4)) |
22 b = ones((3, 4)) |
23 and b will be |
23 and b will be |
24 b |
24 b |
25 similarly, if we already have an array, and we want to create one more array with the same shape and initial values to be one, for that we will use |
25 similarly, say we already have an array, and we want to create one more array with the same shape and initial values to be one, for that we will use |
26 d = ones_like(c) |
26 d = ones_like(c) |
27 and d will be 3x3 array with all values 1 |
27 and d will be 3x3 array with all values 1 |
28 |
28 |
29 Similarly there are functions like zeros and zeros_like which initialize array with all values being 0. One more useful function available is 'identity', it create identity matrix(array) of given order |
29 Similarly there are functions like zeros and zeros_like which initialize array with all values being 0. One more useful function available is 'identity', it create identity matrix(array) of given order |
30 i = identity(3) |
30 i = identity(3) |