summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--accessing_parts_of_arrays/script.rst92
-rw-r--r--getting_started_with_arrays/script.rst81
-rw-r--r--matrices/script.rst18
-rw-r--r--parsing_data/script.rst98
4 files changed, 148 insertions, 141 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 36bc001..ac8c455 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
diff --git a/parsing_data/script.rst b/parsing_data/script.rst
index fdbdc35..87a337f 100644
--- a/parsing_data/script.rst
+++ b/parsing_data/script.rst
@@ -57,7 +57,7 @@ Invoke the ipython interpreter by typing ipython on your terminal.
.. L4
-{{{ Open the tutorial }}}
+{{{ Open the terminal }}}
::
ipython
@@ -73,8 +73,6 @@ corresponds to a student.
{{{ Open the file sslc.txt and show }}}
-.. R5
-
.. L6
{{{ show the slide 'Data set' }}}
@@ -88,14 +86,13 @@ language,first language, maths, science and social and total marks.
Our job is to calculate the arithmetic mean of all the maths marks in
the region "B".
-Now let us understand, what is meant by 'parsing data'.
-
.. L7
{{{ Open the file sslc.txt and show }}}
.. R7
+Now let us understand, what is meant by 'parsing data'.
From the input file, we can see that the data we have is in the form of
text. Parsing this data is all about reading it and converting it into a
form which can be used for computations -- in our case,it will be a
@@ -135,8 +132,8 @@ all the spaces are treated as one big space.
.. R11
-the function ``split`` can also split on a string of our choice.
-This is acheived by passing that as an argument. But first lets define
+The function ``split`` can also split on a string of our choice.
+This is achieved by passing that as an argument. But first lets define
a sample record from the file.
.. L11
@@ -167,18 +164,18 @@ Pause the video here, try out the following exercise and resume the video
Split the variable line using a space as argument. Is it same as
splitting without an argument ?
+.. R14
+
+Switch to terminal for the solution
+
.. L14
{{{ continue from paused state }}}
-
{{{ Switch to the terminal }}}
-
::
record.split()
-.. R14
-
.. L15
{{{ Show slide with Solution 1 }}}
@@ -186,7 +183,7 @@ Pause the video here, try out the following exercise and resume the video
.. R15
We see that when we split on space, multiple whitespaces are not clubbed
-as one and there is an empty string everytime there are two consecutive
+as one and there is an empty string every time there are two consecutive
spaces.
.. L16
@@ -213,7 +210,7 @@ a string by typing
.. R17
-We can see that strip removes all the whitespace around the sentence
+We can see that strip removes all the whitespace around the sentence.
Pause the video here, try out the following exercise and resume the video
@@ -225,23 +222,27 @@ Pause the video here, try out the following exercise and resume the video
What happens to the white space inside the sentence when it is stripped
+.. R19
+
+Switch to the terminal for solution
+
.. L19
{{{ continue from paused state }}}
-
{{{ Switch to the terminal }}}
-
::
a_str = " white space "
a_str.strip()
-.. R19
+.. R20
We see that, the whitespace inside the sentence is only removed and the
rest remains unaffected.
-.. R20
+.. L20
+
+.. R21
By now we know enough to separate fields from the record and to strip
out any white space. The only road block we now have, is conversion of
@@ -253,14 +254,14 @@ and mathematical operations are not possible on them. We must convert
them into numbers (integers or floats), before we can perform mathematical
operations on them.
-.. L20
+.. L21
-.. R21
+.. R22
-We shall look at converting strings into floats. We define a float string
+We shall now look at converting strings into floats. We define a float string
first. Type
-.. L21
+.. L22
::
mark_str = "1.25"
@@ -268,39 +269,42 @@ first. Type
type(mark_str)
type(mark)
-.. R22
+.. R23
We can see that string is converted to float. We can perform mathematical
operations on them now.
Pause the video here, try out the following exercise and resume the video
-.. L22
+.. L23
-.. R23
+.. L24
{{{ Show slide with Exercise 3 }}}
-.. L23
+.. R24
What happens if you do int("1.25")
-.. L24
+.. R25
-{{{ continue from paused state }}}
+Switch to the terminal for solution
+.. L25
+
+{{{ continue from paused state }}}
{{{ Switch to the terminal }}}
::
int("1.25")
-.. R24
+.. R26
It raises an error since converting a float string into integer directly
is not possible. It involves an intermediate step of converting to float.
Hence we will have to do the following conversions.
-.. L25
+.. L26
::
dcml_str = "1.25"
@@ -309,10 +313,10 @@ Hence we will have to do the following conversions.
number = int(flt)
number
-.. R25
-
.. R26
+.. R27
+
Using ``int``, it is also possible to convert float into integers.
Now that we have all the machinery required to parse the file, let us
@@ -320,9 +324,9 @@ solve the problem. We first read the file line by line and parse each
record. We then see if the region code is B and store the marks
accordingly.
-.. L26
-
.. L27
+
+.. L28
::
math_marks_B = [] # an empty list to store the marks
@@ -338,46 +342,46 @@ accordingly.
if region_code == "B":
math_marks_B.append(math_mark)
-.. R27
-
.. R28
+.. R29
+
Now we have all the math marks of region "B" in the list math_marks_B.
To get the mean, we just have to sum the marks and divide by the length.
-.. L28
+.. L29
::
math_marks_mean = sum(math_marks_B) / len(math_marks_B)
math_marks_mean
-.. R29
+.. R30
Hence we get our final output. This is how we split and read such a huge
data and perform computations on it.
-.. L29
-
.. L30
+.. L31
+
{{{ Show summary slide }}}
-.. R30
+.. R31
This brings us to the end of the tutorial.
In this tutorial, we have learnt to,
1. Tokenize a string using various delimiters like semi-colons.
- #. Split a data seperated by delimiters by using the function ``split()``.
+ #. Split a data separated by delimiters by using the function ``split()``.
#. Get rid of extra white spaces around using the ``strip()`` function.
#. Convert datatypes of numbers from one type to another.
#. Parse input data and perform computations on it.
-.. L31
+.. L32
{{{Show self assessment questions slide}}}
-.. R31
+.. R32
Here are some self assessment questions for you to solve
@@ -394,11 +398,11 @@ Here are some self assessment questions for you to solve
- Error
- "20"
-.. L32
+.. L33
{{{solution of self assessment questions on slide}}}
-.. R32
+.. R33
And the answers,
@@ -411,11 +415,11 @@ And the answers,
3. int("20.0") will give an error, because converting a float string,
20.0, directly into integer is not possible.
-.. L33
+.. L34
{{{ Show the Thank you slide }}}
-.. R33
+.. R34
Hope you have enjoyed this tutorial and found it useful.
Thank you.