diff options
-rw-r--r-- | accessing_parts_of_arrays/script.rst | 92 | ||||
-rw-r--r-- | getting_started_with_arrays/script.rst | 81 | ||||
-rw-r--r-- | matrices/script.rst | 18 |
3 files changed, 97 insertions, 94 deletions
diff --git a/accessing_parts_of_arrays/script.rst b/accessing_parts_of_arrays/script.rst index c4a74fe..aeb1938 100644 --- a/accessing_parts_of_arrays/script.rst +++ b/accessing_parts_of_arrays/script.rst @@ -317,7 +317,7 @@ We can see the contents of the image, using the command We do not see white and black because, ``pylab`` has mapped white and black to different colors. -This can be changed by using a different colormap. +This can be changed by using a different color map. To see that ``I`` is really, just an array, we say, I, at the prompt @@ -460,6 +460,10 @@ Pause the video here, try out the following exercise and resume the video. Obtain the elements [[23, 24], [33, -34]] from C. +.. R40 + +Switch to the terminal for solution. + .. L40 {{{continue from paused state}}} @@ -468,10 +472,8 @@ Pause the video here, try out the following exercise and resume the video. C[1:3, 2:4] -.. R40 +.. R41 -Switch to the terminal for solution. -<Type the command> C[1:3, 2:4] will give us the required elements. Now, we wish to obtain the top left quarter of the image. How do @@ -484,35 +486,39 @@ columns. I[:150, :150] -.. R41 +.. R42 I[:150, :150] gives us the top-left corner of the image. -.. R42 +.. R43 We use the ``imshow`` command to see the slice we obtained in the form of an image and confirm. -.. L42 +.. L43 :: imshow(I[:150, :150]) -.. R43 +.. R44 Pause the video here, try out the following exercise and resume the video. -.. L43 - .. L44 +.. L45 + {{{ show slide containing exercise 5 }}} -.. R44 +.. R45 Obtain the square in the center of the image. -.. L45 +.. R46 + +Switch to the terminal for solution. + +.. L46 {{{continue from paused state}}} {{{ Switch to the terminal }}} @@ -520,10 +526,8 @@ Pause the video here, try out the following exercise and resume the video. imshow(I[75:225, 75:225]) -.. R45 +.. R47 -Switch to the terminal for solution. -<Type the command> Hence, we get the center of the image. Our next goal is to compress the image, using a very simple @@ -537,78 +541,78 @@ We shall first learn the idea of striding using the smaller array C. Suppose we wish to access only the odd rows and columns (first, third, fifth). We do this by, -.. L46 +.. L47 :: C[0:5:2, 0:5:2] -.. R46 - -.. R47 +.. R48 if we wish to be explicit, we say, -.. L47 +.. L48 :: C[::2, ::2] -.. R48 +.. R49 This is very similar to the step specified to the ``range`` function. It specifies, the jump or step in which to move, while accessing the elements. If no step is specified, a default value of 1 is assumed. -.. L48 +.. L49 :: C[1::2, ::2] -.. R49 +.. R50 we get the elements, [[21, 23, 0], [41, 43, 0]] Pause the video here, try out the following exercise and resume the video. -.. L49 - .. L50 +.. L51 + {{{ show slide containing exercise 6 }}} -.. R50 +.. R51 Obtain the following. [[12, 0], [42, 0]] [[12, 13, 14], [0, 0, 0]] -.. L51 +.. R52 + +The solution is on your screen. + +.. L52 {{{continue from paused state}}} {{{ show slide containing Solution 6 }}} -.. R51 - -The solution is on your screen. +.. R53 Now, that we know how to stride over an array, we can drop alternate rows and columns out of the image in I. -.. L52 +.. L53 :: I[::2, ::2] -.. R52 +.. R54 To see this image, we say, -.. L53 +.. L54 :: imshow(I[::2, ::2]) -.. R53 +.. R55 This does not have much data to notice any real difference, but notice that the scale has reduced to show that we have dropped @@ -616,18 +620,16 @@ alternate rows and columns. If you notice carefully, you will be able to observe some blurring near the edges. To notice this effect more clearly, increase the step to 4. -.. L54 +.. L55 :: imshow(I[::4, ::4]) -.. R54 - -.. L55 +.. L56 {{{ show summary slide }}} -.. R55 +.. R56 This brings us to the end of this tutorial. In this tutorial, we have learnt to, @@ -639,11 +641,11 @@ have learnt to, #. Slice and stride on arrays. #. Read images into arrays and manipulate them. -.. L56 +.. L57 {{{Show self assessment questions slide}}} -.. R56 +.. R57 Here are some self assessment questions for you to solve @@ -675,11 +677,11 @@ Change the array to B = array([[10, 11, 10, 11], [20, 21, 20, 21]]) -.. L57 +.. L58 {{{solution of self assessment questions on slide}}} -.. R57 +.. R58 And the answers, @@ -699,11 +701,11 @@ And the answers, B[:2, 2:] = B[:2, :2] -.. L58 +.. L59 {{{ Show the Thank you slide }}} -.. R58 +.. R59 Hope you have enjoyed this tutorial and found it useful. Thank you! diff --git a/getting_started_with_arrays/script.rst b/getting_started_with_arrays/script.rst index 242ac8e..84c1f6b 100644 --- a/getting_started_with_arrays/script.rst +++ b/getting_started_with_arrays/script.rst @@ -192,15 +192,14 @@ Pause the video here, try out the following exercise and resume the video. Find out the shape of the other arrays i.e. a1, a3, ar that we have created. -.. L15 - -{{{ Continue from paused state }}} - .. R15 -It can be done as, +Switch to the terminal for solution -.. L16 +.. L15 + +{{{ Continue from paused state }}} +{{{ Switch to the terminal }}} :: a1.shape @@ -212,7 +211,7 @@ It can be done as, Now let us try to create a new array with a mix of elements and see what will happen, -.. L17 +.. L16 :: a4 = array([1,2,3,'a string']) @@ -224,7 +223,7 @@ arrays handle elements with the same datatype, but it didn't raise an error. Let us check the values in the new array created. Type a4 in the terminal, -.. L18 +.. L17 :: a4 @@ -240,6 +239,8 @@ Also,if you have noticed,we got something like 'dtype S8' in the output. dtype is nothing but the datatype which is the minimum type required to hold the objects in the sequence. +.. L18 + .. L19 {{{ switch to the next slide, identity & zeros methods }}} @@ -257,6 +258,8 @@ The function ``identity()`` takes an integer argument which specifies the size of the desired matrix, .. L20 + +{{{ Switch to the terminal }}} :: identity(3) @@ -289,19 +292,18 @@ Pause the video here, try out the following exercise and resume the video. .. R22 -We learned two functions ``identity()`` and ``zeros()``, find out more -about the functions ``zeros_like()``, ``ones()``, ``ones_like()``. +Find out about the functions + - zeros_like() + - ones() + - ones_like() -.. L23 - -{{{ continue from paused state }}} -{{{ Switch to the terminal }}} +< pause for some time and then continue > .. R23 Try the following, first check the value of a1, -.. L24 +.. L23 :: a1 @@ -311,16 +313,17 @@ Try the following, first check the value of a1, We see that ``a1`` is a single dimensional array, Let us now try a1*2 -.. L25 +.. L24 :: a1 * 2 .. R25 + It returned a new array with all the elements multiplied by 2. Now let us again check the contents of a1 -.. L26 +.. L25 :: a1 @@ -329,17 +332,15 @@ Now let us again check the contents of a1 note that the value of a1 still remains the same. -.. R27 - Similarly with addition, -.. L27 +.. L26 :: a1 + 2 a1 -.. R28 +.. R27 it returns a new array, with all the elements summed with two. But again notice that the value of a1 has not been changed. @@ -347,53 +348,53 @@ again notice that the value of a1 has not been changed. You may change the value of a1 by simply assigning the newly returned array as, -.. L28 +.. L27 :: a1 += 2 -.. R29 +.. R28 -Notice the change in elements of a, +Notice the change in elements of a by typing 'a' -.. L29 +.. L28 :: a -.. R30 +.. R29 We can use all the mathematical operations with arrays, Now let us try this -.. L30 +.. L29 :: a1 = array([1,2,3,4]) a2 = array([1,2,3,4]) a1 + a2 -.. R31 +.. R30 This returns an array with element by element addition -.. L31 +.. L30 :: a1 * a2 -.. R32 +.. R31 a1*a2 returns an array with element by element multiplication, notice that it does not perform matrix multiplication. -.. L32 +.. L31 -.. L33 +.. L32 {{{ switch to summary slide }}} -.. R33 +.. R32 This brings us to the end of the end of this tutorial.In this tutorial, we have learnt to, @@ -408,13 +409,13 @@ we have learnt to, - zeros() & zeros_like() - ones() & ones_like() -.. L34 +.. L33 {{{Show self assessment questions slide}}} -.. R34 +.. R33 -Here are some self assessment questionss for you to solve +Here are some self assessment questions for you to solve 1. ``x = array([1, 2, 3], [5, 6, 7])`` is a valid statement @@ -435,11 +436,11 @@ Here are some self assessment questionss for you to solve - Both statement A and B are correct. - Both statement A and B are incorrect. -.. L35 +.. L34 {{{solution of self assessment questions on slide}}} -.. R35 +.. R34 And the answers, @@ -453,11 +454,11 @@ And the answers, 2. The function ``ones_like()`` returns an array of ones with the same shape and type as a given array. -.. L36 +.. L35 {{{ switch to thank you slide }}} -.. R36 +.. R35 Hope you have enjoyed this tutorial and found it useful. Thank you! diff --git a/matrices/script.rst b/matrices/script.rst index 68eb709..0979882 100644 --- a/matrices/script.rst +++ b/matrices/script.rst @@ -144,10 +144,10 @@ m3 can be created as, .. R11 -Let us now move to matrix matrix operations. +Let us now move to matrix operations. We can do matrix addition and subtraction easily. m3+m2 does element by element addition, that is matrix addition. -Note that both the matrices are of the same order. +Note that both the matrices should be of the same order. .. L11 :: @@ -187,8 +187,8 @@ Matrix multiplication in matrices are done using the function ``dot()`` .. R15 -Due to size mismatch the multiplication could not be done and it -returned an error, +Due to size mismatch, the multiplication could not be done and it +returned an error. Now let us see an example for matrix multiplication. For doing matrix multiplication we need to have two matrices of the order n by m and m @@ -306,7 +306,7 @@ And the Frobenius norm of the matrix ``im5`` can be found out as, .. R25 -Thus we have successfully obtained the frobenius norm of the matrix m5 +Thus we have successfully obtained the Frobenius norm of the matrix m5 Pause the video here, try out the following exercise and resume the video. @@ -355,7 +355,7 @@ The norm of a matrix can be found out using the method .. R30 -Inorder to find out the Frobenius norm of the matrix im5, +In order to find out the Frobenius norm of the matrix im5, we do, .. L30 @@ -377,7 +377,7 @@ And to find out the Infinity norm of the matrix im5, we do, .. R32 This is easier when compared to the code we wrote. Read the documentation -of ``norm`` to read up more about ord and the possible type of norms +of ``norm`` to read up more about ``ord`` and the possible type of norms the norm function produces. Now let us find out the determinant of a the matrix m5. @@ -545,10 +545,10 @@ And the answers, 2. False. ``eig(A)[0]`` and ``eigvals(A)`` are same, that is both will give the - eigen values of matrrix A. + eigen values of matrix A. 3. ``norm(A,ord='fro')`` and ``norm(A)`` are same, since the order='fro' - stands for frobenius norm. Hence true. + stands for Frobenius norm. Hence true. .. L45 |