arrays.txt
changeset 75 3a94917224e9
parent 72 7d4ed969a942
child 125 27ddf1255daa
equal deleted inserted replaced
74:12729a0a1893 75:3a94917224e9
     1 Hello friends and welcome to this tutorial on Matrices.
     1 Hello friends and welcome to this tutorial on Matrices.
     2 In python all matrix 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 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.
     3 We have already seen in previous session that how arrays are better suited for certain mathematical operations. In this session we shall see how to perform efficient matrix operations using arrays. We shall see how to create them, how to initialize them, how to manipulate and use them to perform some basic image processing. For this tutorial we shall need the lena.png image. Hope you have the image with you. 
     4 
     4 
     5 Let's now start off. As you can see our lena image is on the desktop, so first let's navigate to the desktop by cd Desktop.
     5 Let's now start off. As you can see our lena image is on the desktop, so first let's navigate to the desktop by cd Desktop.
     6 
     6 
     7 Let's now fire up Ipython, ipython -pylab
     7 Let's now fire up Ipython, ipython -pylab
     8 
     8 
    31 and d is a 3x3 array with all values equal to 1
    31 and d is a 3x3 array with all values equal to 1
    32 
    32 
    33 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 of given order
    33 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 of given order
    34 i = identity(3)
    34 i = identity(3)
    35 i
    35 i
    36 i = identity(5)
       
    37 i
       
    38 
    36 
    39 Note that identity takes just one argument since identity matrix is always a square matrix.
    37 Note that identity takes just one argument since identity matrix is always a square matrix.
    40 
    38 
    41 ----------------
    39 ----------------
    42 Now that we have covered creation of arrays, we shall see how to access and change values of particular elements. 
    40 Now that we have covered creation of arrays, we shall see how to access and change values of particular elements. 
    71 returns the third column.
    69 returns the third column.
    72 here the ':' part mentioned for row value symbolises entire row.
    70 here the ':' part mentioned for row value symbolises entire row.
    73 the c[1] we were using earlier can also be written as c[1,:]
    71 the c[1] we were using earlier can also be written as c[1,:]
    74 
    72 
    75 ':' actually takes two value. for any row or column we can mention
    73 ':' actually takes two value. for any row or column we can mention
    76 start:end values, and rows/columns starting for 'start' till 'end' will be returned. Lets try some examples for better understanding
    74 start:end values, and rows or columns starting for 'start' till 'end' will be returned. Lets try some examples for better understanding
    77 c[0:2,:]
    75 c[0:2,:]
    78 results in rows starting from row zero(0) upto the second row and all columns. Note here that 'end', in this case, '2' will not be included in resulting array.
    76 results in rows starting from row zero(0) upto the second row and all columns. Note here that 'end', in this case, '2' will not be included in resulting array.
    79 
    77 
    80 c[1:3,:] 
    78 c[1:3,:] 
    81 gives second and third row.
    79 gives second and third row.