diff options
author | Amit Sethi | 2010-11-08 01:56:03 +0530 |
---|---|---|
committer | Amit Sethi | 2010-11-08 01:56:03 +0530 |
commit | bf83e16caf164cdbcb3ddd72f44833109b989b97 (patch) | |
tree | d2d14c96af50041aa9cc29d8c3595aa8bcb16d3e | |
parent | e09d107f6a3c7ddd290e4390158f682c1ca2b0b4 (diff) | |
parent | 1535316de3744cb31b7f1eaa5006f30a15d0f31c (diff) | |
download | st-scripts-bf83e16caf164cdbcb3ddd72f44833109b989b97.tar.gz st-scripts-bf83e16caf164cdbcb3ddd72f44833109b989b97.tar.bz2 st-scripts-bf83e16caf164cdbcb3ddd72f44833109b989b97.zip |
Merging changes
28 files changed, 621 insertions, 326 deletions
diff --git a/accessing-pieces-arrays/script.rst b/accessing-pieces-arrays/script.rst index 1c7b9b3..b6567a4 100644 --- a/accessing-pieces-arrays/script.rst +++ b/accessing-pieces-arrays/script.rst @@ -16,11 +16,12 @@ .. 1. getting started with arrays - +.. #[anand: internal reviewer not mentioned] .. Author : Puneeth Internal Reviewer : External Reviewer : - Checklist OK? : <put date stamp here, if OK> [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <06-11-2010, Anand, OK> [2010-10-05] Script ------ @@ -126,12 +127,11 @@ or C[-1] = 0 -Now, how do we access one column of C? As with accessing -individual elements, the column is the second parameter to be -specified (after the comma). The first parameter, is now replaced -with a ``:`` to say, that we want all the elements of that -dimension, instead of one particular element. We access the third -column by +Now, how do we access one column of C? As with accessing individual +elements, the column is the second parameter to be specified (after +the comma). The first parameter, is replaced with a ``:``. This +specifies that we want all the elements of that dimension, instead of +just one particular element. We access the third column by :: @@ -230,7 +230,7 @@ We say, to get the elements of rows indexed from 0 to 3, 3 not included and column indexed 2. Note that, the index before the colon is -included and the index after it is not included, in the slice that +included and the index after it is not included in the slice that we have obtained. This is very similar to the ``range`` function, where ``range`` returns a list, in which the upper limit or stop value is not included. @@ -269,11 +269,10 @@ gives the elements [11, 21, 31, 41] gives the elements [21, 31, 41, 0] -Note that when specifying ranges, if you are starting from or -going up-to the end, the corresponding element may be dropped. So, -in the previous example to obtain [11, 21, 31, 41], we could have -simply said, -:: +Note that when specifying ranges, if you are starting from the +beginning or going up-to the end, the corresponding element may be +dropped. So, in the previous example to obtain [11, 21, 31, 41], we +could have simply said, :: C[:4, 0] @@ -323,7 +322,7 @@ Following is an exercise that you must do. %%5%% Obtain the square in the center of the image. -Following is an exercise that you must do. +Please, pause the video here. Do the exercises and then continue. {{ show slide containing Solution 5 }} @@ -383,7 +382,7 @@ gives the elements [[12, 0], [42, 0]] gives the elements [[12, 13, 14], [0, 0, 0]] -Now, that we know how to stride over an image, we can drop +Now, that we know how to stride over an array, we can drop alternate rows and columns out of the image in I. :: @@ -423,5 +422,5 @@ Thank you! mode: rst indent-tabs-mode: nil sentence-end-double-space: nil - fill-column: 75 + fill-column: 70 End: diff --git a/accessing-pieces-arrays/slides.org b/accessing-pieces-arrays/slides.org index 1f33426..82801ca 100644 --- a/accessing-pieces-arrays/slides.org +++ b/accessing-pieces-arrays/slides.org @@ -2,7 +2,7 @@ #+LaTeX_CLASS_OPTIONS: [presentation] #+BEAMER_FRAME_LEVEL: 1 -#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} +#+BEAMER_HEADER_EXTRA: \usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent} #+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) #+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC diff --git a/accessing-pieces-arrays/slides.tex b/accessing-pieces-arrays/slides.tex index 8a0f1a9..a3e4c6d 100644 --- a/accessing-pieces-arrays/slides.tex +++ b/accessing-pieces-arrays/slides.tex @@ -1,4 +1,4 @@ -% Created 2010-10-26 Tue 12:11 +% Created 2010-11-02 Tue 17:47 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -8,7 +8,6 @@ \usepackage{float} \usepackage{wrapfig} \usepackage{soul} -\usepackage{t1enc} \usepackage{textcomp} \usepackage{marvosym} \usepackage{wasysym} @@ -28,7 +27,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \author{FOSSEE} \date{} -\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} +\usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} \maketitle @@ -57,7 +56,8 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \frametitle{Sample Arrays} \label{sec-2} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} In []: A = array([12, 23, 34, 45, 56]) In []: C = array([[11, 12, 13, 14, 15], @@ -65,7 +65,7 @@ In []: C = array([[11, 12, 13, 14, 15], [31, 32, 33, 34, 35], [41, 42, 43, 44, 45], [51, 52, 53, 54, 55]]) -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame} \frametitle{Question 1} @@ -77,9 +77,10 @@ In []: C = array([[11, 12, 13, 14, 15], \frametitle{Solution 1} \label{sec-4} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} In []: C[:, -1] = 0 -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame} \frametitle{Question 2} @@ -91,9 +92,10 @@ In []: C[:, -1] = 0 \frametitle{Solution 2} \label{sec-6} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} In []: A[:] = [11, 12, 13, 14, 15] -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame} \frametitle{squares.png} @@ -117,11 +119,12 @@ In []: A[:] = [11, 12, 13, 14, 15] \frametitle{Solution 3} \label{sec-9} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} In []: C[1, 1:3] In []: C[0:4, 0] In []: C[1:5, 0] -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame} \frametitle{Question 4} @@ -133,9 +136,10 @@ In []: C[1:5, 0] \frametitle{Solution 4} \label{sec-11} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} In []: C[1:3, 2:4] -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame} \frametitle{Question 5} @@ -147,28 +151,31 @@ In []: C[1:3, 2:4] \frametitle{Solution 5} \label{sec-13} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} In []: imshow(I[75:225, 75:225]) -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Question 6} \label{sec-14} Obtain the following -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} [[12, 0], [42, 0]] [[12, 13, 14], [0, 0, 0]] -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Solution 6} \label{sec-15} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} In []: C[::3, 1::3] In []: C[::4, 1:4] -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame} \frametitle{Summary} @@ -176,7 +183,7 @@ In []: C[::4, 1:4] You should now be able to -- \begin{itemize} -\item Manipulate 1D \& Multi dimensional arrays +\item Manipulate single \& multi dimensional arrays \begin{itemize} \item Access and change individual elements diff --git a/dictionaries/quickref.tex b/dictionaries/quickref.tex new file mode 100644 index 0000000..40c2256 --- /dev/null +++ b/dictionaries/quickref.tex @@ -0,0 +1,20 @@ +Defining dictionary:\\ +{\ex \lstinline| d = {'k1':'v1', 'k2':'v2'}|} + +Access value using key in dictionary:\\ +{\ex \lstinline| print d['k1']|} + +Add key-value pair to dictionary:\\ +{\ex \lstinline| d['k3'] = 'v3'|} + +Delete key-value from dictionary:\\ +{\ex \lstinline| del d['k1']|} + +Check container-ship of key in dictionary:\\ +{\ex \lstinline| 'k2' in d|} + +List of keys in dictionary:\\ +{\ex \lstinline| d.keys()|} + +List of values in dictionary:\\ +{\ex \lstinline| d.values()|} diff --git a/getting-started-files/script.rst b/getting-started-files/script.rst index 1a77eb8..bd3dc9b 100644 --- a/getting-started-files/script.rst +++ b/getting-started-files/script.rst @@ -17,7 +17,8 @@ .. Author : Puneeth Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in> External Reviewer : - Checklist OK? : <put date stamp here, if OK> [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <06-11-2010, Anand, OK> [2010-10-05] Script ------ @@ -69,7 +70,7 @@ Now, let us see what is in ``pend``, by typing print pend -We can see that ``pend`` has all the data of file. Type just ``pend`` +We can see that ``pend`` has all the data of the file. Type just ``pend`` to see more explicitly, what it contains. :: @@ -77,7 +78,7 @@ to see more explicitly, what it contains. Following is an exercise that you must do. -.. #[[Anoop:add context switch to next slide - questions]] +{{ show slide with Question 1 }} %%1%% Split the variable into a list, ``pend_list``, of the lines in the file. Hint, use the tab command to see what methods the string @@ -85,14 +86,7 @@ variable has. Please, pause the video here. Do the exercise and then continue. -.. #[punch: should this even be put? add dependency to strings LO, -.. where we mention that strings have methods for manipulation. hint: -.. use splitlines()] - -.. #[[Anoop: let us have it here, let us consider this as a - refresher]] - -.. #[[Anoop:add context switch to next slide - solution]] +{{ show slide with Solution 1 }} :: @@ -104,12 +98,6 @@ Now, let us learn to read the file line-by-line. But, before that we will have to close the file, since the file has already been read till the end. -.. #[punch: should we mention file-pointer?] - -.. #[[Anoop: I think we can say that ``f`` is a file pointer which - points to the next line/data to be read from the file. We could - skip details.]] - Let us close the file opened into f. :: @@ -146,12 +134,9 @@ the file line-wise and print each of the lines. for line in f: print line -As we already know, ``line`` is just a dummy variable, and not a -keyword. We could have used any other variable name, but ``line`` -seems meaningful enough. - -.. #[[Anoop: using dummy variable doesn't seem correct, can say line - is a variable]] +As we already know, ``line`` is variable, sometimes called the loop +variable, and it is not a keyword. We could have used any other +variable name, but ``line`` seems meaningful enough. Instead of just printing the lines, let us append them to a list, ``line_list``. We first initialize an empty list, ``line_list``. @@ -181,15 +166,12 @@ with the newline characters. If you noticed, ``pend_list`` did not contain the newline characters, because the string ``pend`` was split on the newline characters. -.. #[[Anoop: I think we need to tell them that each line can be - stripped and appended to list to avoid the problem of newline - characters.]] +Using some string methods, that we shall look at in the tutorial on +strings, we can strip out the newline characters from the lines. .. #[[Anoop: I think the code that are required to be typed can be added to the slide.]] -.. #[[Anoop: Context switches are to be added.]] - {{{ show the summary slide }}} That brings us to the end of this tutorial. In this tutorial we diff --git a/getting-started-ipython/script.rst b/getting-started-ipython/script.rst index 5d8056c..703cccc 100644 --- a/getting-started-ipython/script.rst +++ b/getting-started-ipython/script.rst @@ -17,6 +17,7 @@ .. Author : Puneeth Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in> + Language Review : Bhanukiran External Reviewer : Checklist OK? : <put date stamp here, if OK> [2010-10-05] @@ -74,6 +75,7 @@ at the prompt. IPython promptly gives back the output as 3. Notice that the output is displayed with an ``Out[1]`` indication. .. #[[Anoop: I think we can illustrate In [] and Out[] in slides]] +.. #[[Puneeth: I think we can do that on the terminal?]] Let's try out few other mathematical operations. :: @@ -94,15 +96,11 @@ Now, let's change the previous command ``print 1+2`` to ``print 10*2``. We use the up arrow again to navigate to the previous command and use the left arrow key to move the cursor on to the + symbol and then use the delete key to remove it and type 0 and * to change the -expression to the required one. We hit enter to see the output of +expression as required. We hit enter to see the output of ``print``. -.. #[[Anoop: We could create a slide with heading Tab Completion and - give the question as an exercise, basically I feel more slides - should be used]] - Now, let's say we want to use the function ``round``. We type ``ro`` -at the prompt and hit the tab key. As you can see, the IPython +at the prompt and hit the tab key. As you can see, IPython completes the command. This feature is called the tab-completion. Now, we remove all the characters and just type ``r`` and then hit @@ -111,8 +109,6 @@ possibilities. It just lists out all the possible completions. Following is an exercise that you must do. -.. #[[Anoop: Include slides for exercises]] - %%1%% Type ``ab`` and hit tab to see what happens. Next, just type ``a`` and hit tab to see what happens. @@ -127,6 +123,9 @@ help features of ipython to find this out. .. #[[Anoop: Another slide which says about ? mark and round? etc, as few people cannot just follow by listening (like me) :)]] +.. #[Punch: These things are shown on the terminal. I feel we don't +.. need slide, here I guess.] + To get the help of any function, we first type the function, ``abs`` in our case and then add a ? at the end and hit enter. @@ -147,8 +146,6 @@ and we do get back 10.5. Following is an exercise that you must do. -.. #[[Anoop: add slide]] - %%2%% Look-up the documentation of ``round`` and see how to use it. Please, pause the video here. Do the exercise and then continue. @@ -166,8 +163,6 @@ The function ``round``, rounds a number to a given precision. Following are exercises that you must do. -.. #[[Anoop: add slide]] - %%3%% Check the output of:: round(2.48) @@ -182,7 +177,7 @@ Please, pause the video here. Do the exercises and then continue. We get 2.0, 2.5 and 2.48, which are what we expect. -Let's now see how to correct typing errors that we make when typing at +Let's now see how to correct typing errors that we make while typing at the terminal. As already shown, if we haven't hit the enter key already, we could navigate using the arrow keys and make deletions using delete or backspace key and correct the errors. @@ -201,8 +196,6 @@ prompt. Following is an exercise that you must do. -.. #[[Anoop: add slide]] - %%4%% Try typing round(2.484, and hit enter. and then cancel the command using Ctrl-C. Then, type the command, round(2.484, 2) and resume the video. @@ -222,6 +215,8 @@ This brings us to the end of the tutorial on getting started with .. #[[Anoop: add slides for interrupts, navigating history, I feel even a single point will also do]] +.. #[Puneeth: I don't feel these things cannot be shown on a slide.] + In this tutorial we have learnt, how to {{{ show the outline/summary slide. }}} diff --git a/getting-started-ipython/slides.org b/getting-started-ipython/slides.org index ade1aae..d729cca 100644 --- a/getting-started-ipython/slides.org +++ b/getting-started-ipython/slides.org @@ -36,6 +36,44 @@ + use tab-completion + look-up documentation of functions + interrupt incomplete or incorrect commands +* Question 1 + Type =ab= and hit tab to see what happens. Next, just type =a= and + hit tab to see what happens. +* Solution 1 + =ab= tab completes to =abs= and =a<tab>= gives us a list of all the + commands starting with a. +* Question 2 + Look-up the documentation of =round= and see how to use it. +* Solution 2 + =round?= +* Question 3 + Check the output of + #+begin_src python + round(2.48) + round(2.48, 1) + round(2.48, 2) + + round(2.484) + round(2.484, 1) + round(2.484, 2) + #+end_src + Look-up the documentation of =round= and see how to use it. +* Solution 3 + We get 2.0, 2.5 and 2.48, which are what we expect. +* Question 4 + Try typing =round(2.484=, and hit enter. and then cancel the command + using Ctrl-C. Then, type the command, =round(2.484, 2)= and resume + the video. +* Solution 4 + #+begin_src python + round(2.484 + ^C + + round(2.484, 2) + #+end_src + + + * Summary + invoking and quitting the ~ipython~ interpreter + navigating the history diff --git a/getting-started-ipython/slides.tex b/getting-started-ipython/slides.tex index 20af21e..310db35 100644 --- a/getting-started-ipython/slides.tex +++ b/getting-started-ipython/slides.tex @@ -1,4 +1,4 @@ -% Created 2010-10-26 Tue 10:33 +% Created 2010-11-05 Fri 20:59 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -8,7 +8,6 @@ \usepackage{float} \usepackage{wrapfig} \usepackage{soul} -\usepackage{t1enc} \usepackage{textcomp} \usepackage{marvosym} \usepackage{wasysym} @@ -55,9 +54,78 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{itemize} \end{frame} \begin{frame} -\frametitle{Summary} +\frametitle{Question 1} \label{sec-2} + Type \texttt{ab} and hit tab to see what happens. Next, just type \texttt{a} and + hit tab to see what happens. +\end{frame} +\begin{frame} +\frametitle{Solution 1} +\label{sec-3} + + \texttt{ab} tab completes to \texttt{abs} and \texttt{a<tab>} gives us a list of all the + commands starting with a. +\end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-4} + + Look-up the documentation of \texttt{round} and see how to use it. +\end{frame} +\begin{frame} +\frametitle{Solution 2} +\label{sec-5} + + \texttt{round?} +\end{frame} +\begin{frame}[fragile] +\frametitle{Question 3} +\label{sec-6} + + Check the output of +\lstset{language=Python} +\begin{lstlisting} +round(2.48) +round(2.48, 1) +round(2.48, 2) + +round(2.484) +round(2.484, 1) +round(2.484, 2) +\end{lstlisting} + Look-up the documentation of \texttt{round} and see how to use it. +\end{frame} +\begin{frame} +\frametitle{Solution 3} +\label{sec-7} + + We get 2.0, 2.5 and 2.48, which are what we expect. +\end{frame} +\begin{frame} +\frametitle{Question 4} +\label{sec-8} + + Try typing \texttt{round(2.484}, and hit enter. and then cancel the command + using Ctrl-C. Then, type the command, \texttt{round(2.484, 2)} and resume + the video. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 4} +\label{sec-9} + +\lstset{language=Python} +\begin{lstlisting} +round(2.484 +^C + +round(2.484, 2) +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-10} + \begin{itemize} \item invoking and quitting the \texttt{ipython} interpreter \item navigating the history @@ -68,7 +136,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame} \frametitle{Thank you!} -\label{sec-3} +\label{sec-11} \begin{block}{} \begin{center} diff --git a/getting-started-with-arrays/quickref.tex b/getting-started-with-arrays/quickref.tex new file mode 100644 index 0000000..10714c4 --- /dev/null +++ b/getting-started-with-arrays/quickref.tex @@ -0,0 +1,14 @@ +Creating an array:\\ +{\ex \lstinline| a = array([[1,2,3,4],[5,6,7,8]])|} + +Finding shape of array:\\ +{\ex \lstinline| a.shape|} + +Reshape an array:\\ +{\ex \lstinline| a.reshape(4,2)|} + +Creating identity matrix:\\ +{\ex \lstinline| identity(3)|} + +Creating matrix with all zeros:\\ +{\ex \lstinline| z = zeros((4,2))|} diff --git a/getting-started-with-arrays/script.rst b/getting-started-with-arrays/script.rst index 0889032..7f744d3 100644 --- a/getting-started-with-arrays/script.rst +++ b/getting-started-with-arrays/script.rst @@ -34,14 +34,15 @@ Welcome to the spoken tutorial on getting started with arrays. {{{ switch to next slide, outline slide }}} -In this tutorial, we will learn about arrays, how to convert a list into an -array and also why an array is preferred over lists. And array operations. +In this tutorial, we will learn about arrays, we will learn how to convert +a list into an array array operations and also why an array is preferred +over lists. .. #[Puneeth: Fix the grammar above.] {{{ switch to next slide on overview of array }}} -Arrays are homogeneous data structures, unlike lists, arrays cannot have +Arrays are homogeneous data structures. Unlike lists, arrays cannot have heterogeneous data elements, that is, it can have only one type of data type, either all integers, or strings, or float, and not a mix. @@ -52,7 +53,7 @@ type, either all integers, or strings, or float, and not a mix. type of data, ....] Arrays are really fast in mathematical operations when compared to lists, -it is at least 80 to 100 times faster than lists. +because of the same type of data in arrays. .. #[Puneeth: For what size of an array is that the comparison? @@ -60,8 +61,12 @@ it is at least 80 to 100 times faster than lists. Now let us see how to create arrays. -I am assuming that you have your IPython interpreter running with the -``-pylab`` option, so that you have the required modules loaded. +Run your IPython interpreter with ``-pylab`` option, to load the required +modules to work with arrays. +{{{ take terminal and run the following command }}} +:: + + ipython -pylab .. #[Puneeth: 'I am assuming' doesn't sound right. Ask them to open if it .. is not open?] @@ -73,9 +78,12 @@ To create an array we will use the function ``array()`` as, a1 = array([1,2,3,4]) Notice that here we created a one dimensional array. Also notice the object -we passed to create an array. Now let us see how to create a two -dimensional array. Pause here and try to do it yourself before looking at -the solution. +we passed to create an array. We passed a list to create an array. + +Now let us see how to create a two dimensional array. Pause here and try to +do it yourself before looking at the solution. + +{{{ switch to next slide, creating two dimensional arrays }}} .. #[Puneeth: I don't think this question can be solved by an average .. viewer. Questions during the tutorial, should generally be to re-iterate @@ -85,7 +93,8 @@ the solution. .. list, using the ``array`` function. Bring the later section about .. converting a list, here. A separate section is not necessary, IMHO.] -This is how we create two dimensional arrays. +We create two dimensional array by converting a list of lists to an array +as, :: @@ -94,7 +103,7 @@ This is how we create two dimensional arrays. .. #[Puneeth: Again, you could explain a bit about the fact that we are .. converting a list of lists.] -Let us see an easy method of creating an array with elements 1 to 8. +Now let us use ``arange()`` function to create the same array as before. :: @@ -103,7 +112,7 @@ Let us see an easy method of creating an array with elements 1 to 8. .. #[Puneeth: say, creating the same array as before. for some time I got .. confused .] -And it created a single dimensional array of elements from 1 to 8. +And we obtained a single dimensional array with elements from 1 to 8. :: @@ -158,10 +167,9 @@ check the shape of the arrays we have created so far, :: - a1.shape + a2.shape -``a1.shape`` object is a tuple, and since a1 is a single dimensional array, -it returned a tuple (4,). +``a2.shape`` object is a tuple, and it returned a tuple (2, 4). .. #[Puneeth: first show a 2D array, so that it becomes easier to explain. .. Also, the word ``tuple`` need not be mentioned. ] @@ -172,6 +180,13 @@ Find out the shape of the other arrays that we have created. .. #[Puneeth: solution missing.] +It can be done as, +:: + + a1.shape + a3.shape + ar.shape + {{{ Array can have only a single type of data }}} .. #[Puneeth: I guess, this whole section can be skipped. If you want to @@ -214,9 +229,10 @@ first three elements were integers. .. #[Puneeth: something needs to motivate this. why are we suddenly talking .. of an identity matrix?] -An identity matrix is a square matrix in which all the diagonal elements -are one and rest of the elements zero. We can create an identity matrix -using the method ``identity()``. +Now let us see how to create identity matrix, an identity matrix is a +square matrix in which all the diagonal elements are one and rest of the +elements zero. We can create an identity matrix using the method +``identity()``. The function ``identity()`` takes an integer argument, @@ -224,7 +240,7 @@ The function ``identity()`` takes an integer argument, identity(3) -As you can see the identity method returned a three by three square array +As you can see the identity method returned a three by three square matrix with all the diagonal elements as one and the rest of the elements as zero. .. #[Puneeth: You say array here, matrix there -- it's a bit messed up. @@ -306,8 +322,8 @@ does not perform matrix multiplication. {{{ switch to next slide, summary slide }}} So this brings us to the end of this tutorial, in this tutorial we covered -basics of arrays, how to create an array, converting a list to an array, -basic array operations etc. +basics of arrays, learned how to create an array, saw how to convert a list +to an array, and basic array operations etc. .. #[Puneeth: s/how to create an array/creating an array] diff --git a/getting-started-with-arrays/slides.org b/getting-started-with-arrays/slides.org index ba97f3c..a5b315f 100644 --- a/getting-started-with-arrays/slides.org +++ b/getting-started-with-arrays/slides.org @@ -44,9 +44,12 @@ * Creating Arrays - Creating a 1-dimensional array : In []: a1 = array([1, 2, 3, 4]) + ~[1, 2, 3, 4]~ is a list. +* Creating two-dimensional array - Creating a 2-dimensional array : In []: a2 = array([[1,2,3,4],[5,6,7,8]]) - - Easier method of creating array with consecutive elements. + here we convert a list of lists to an array making a 2-d array. + - Using ~arange()~ function : In []: ar = arange(1,9) * ~reshape()~ method - To reshape an array @@ -67,11 +70,11 @@ * ~.shape~ of array - ~.shape~ To find the shape of the array - : In []: a1.shape + : In []: a2.shape - ~.shape~ returns a tuple of shape * Exercise 2 - Find out the shape of the other arrays(a2, a3, ar) that we have created. + Find out the shape of the other arrays(a1, a3, ar) that we have created. * Homogeneous data - All elements in array should be of same type : In []: a4 = array([1,2,3,'a string']) diff --git a/getting-started-with-arrays/slides.tex b/getting-started-with-arrays/slides.tex index 63a0790..7273c59 100644 --- a/getting-started-with-arrays/slides.tex +++ b/getting-started-with-arrays/slides.tex @@ -1,4 +1,4 @@ -% Created 2010-10-12 Tue 00:20 +% Created 2010-11-07 Sun 15:18 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -87,6 +87,12 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} In []: a1 = array([1, 2, 3, 4]) \end{verbatim} + \texttt{[1, 2, 3, 4]} is a list. +\end{frame} +\begin{frame}[fragile] +\frametitle{Creating two-dimensional array} +\label{sec-4} + \begin{itemize} \item Creating a 2-dimensional array \end{itemize} @@ -95,6 +101,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} In []: a2 = array([[1,2,3,4],[5,6,7,8]]) \end{verbatim} + here we convert a list of lists to an array making a 2-d array. \begin{itemize} \item Easier method of creating array with consecutive elements. \end{itemize} @@ -105,7 +112,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame}[fragile] \frametitle{\texttt{reshape()} method} -\label{sec-4} +\label{sec-5} \begin{itemize} \item To reshape an array @@ -119,7 +126,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame}[fragile] \frametitle{Creating \texttt{array} from \texttt{list}.} -\label{sec-5} +\label{sec-6} \begin{itemize} \item \texttt{array()} method accepts list as argument @@ -137,13 +144,13 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame} \frametitle{Exercise 1} -\label{sec-6} +\label{sec-7} Create a 3-dimensional array of the order (2, 2, 4). \end{frame} \begin{frame}[fragile] \frametitle{\texttt{.shape} of array} -\label{sec-7} +\label{sec-8} \begin{itemize} \item \texttt{.shape} @@ -158,13 +165,13 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame} \frametitle{Exercise 2} -\label{sec-8} +\label{sec-9} Find out the shape of the other arrays(a2, a3, ar) that we have created. \end{frame} \begin{frame}[fragile] \frametitle{Homogeneous data} -\label{sec-9} +\label{sec-10} \begin{itemize} \item All elements in array should be of same type @@ -176,7 +183,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame}[fragile] \frametitle{Implicit type casting} -\label{sec-10} +\label{sec-11} \begin{verbatim} In []: a4 @@ -186,7 +193,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame} \frametitle{\texttt{identity()}, \texttt{zeros()} methods} -\label{sec-11} +\label{sec-12} \begin{itemize} \item \texttt{identity(n)} @@ -197,7 +204,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame} \frametitle{Learning exercise} -\label{sec-12} +\label{sec-13} \begin{itemize} \item Find out about @@ -212,7 +219,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame} \frametitle{Array operations} -\label{sec-13} +\label{sec-14} \begin{itemize} \item \texttt{a1 * 2} @@ -247,7 +254,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame} \frametitle{Summary} -\label{sec-14} +\label{sec-15} In this tutorial we covered, \begin{itemize} @@ -259,7 +266,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame} \frametitle{Thank you!} -\label{sec-15} +\label{sec-16} \begin{block}{} \begin{center} diff --git a/getting-started-with-for/quickref.tex b/getting-started-with-for/quickref.tex new file mode 100644 index 0000000..d106d6d --- /dev/null +++ b/getting-started-with-for/quickref.tex @@ -0,0 +1,6 @@ +For loop:\\ +{\ex \lstinline| for i in range(1,11,2):|} +{\ex \lstinline| s = s + i|} + +Range function:\\ +{\ex \lstinline| range([start,]stop[,step])|} diff --git a/getting-started-with-for/script.rst b/getting-started-with-for/script.rst index a8226fe..014e040 100644 --- a/getting-started-with-for/script.rst +++ b/getting-started-with-for/script.rst @@ -168,6 +168,8 @@ perfect squares and a list of those which are not. The numbers are, 7225, 3268, 3364, 2966, 7056, 5625, 729, 5547, 7056, 576, 2916 +Pause here and try to solve the problem before proceeding further. + {{{ switch to next slide, problem statement of second problem in solved exercise}}} diff --git a/loading-data-from-files/script.rst b/loading-data-from-files/script.rst index ff4ce19..cc2e008 100644 --- a/loading-data-from-files/script.rst +++ b/loading-data-from-files/script.rst @@ -14,10 +14,12 @@ .. 1. getting started with ``ipython`` -.. Author : - Internal Reviewer : +.. #[Anand: author and internal reviewer not mentioned] +.. Author : Puneeth Changanti + Internal Reviewer : Nishanth Amuluru External Reviewer : - Checklist OK? : <put date stamp here, if OK> [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <06-11-2010 Anand, OK> [2010-10-05] Script ------ @@ -96,7 +98,7 @@ equal number of rows. .. cat /home/fossee/pendulum.txt .. #[Nishanth]: The first column is L values and second is T values - from a simle pelculum experiment. + from a simple pendulum experiment. Since you are using the variable names later in the script. Not necessary but can be included also. @@ -133,7 +135,7 @@ Let us now, print the variables L and T, to see what they contain. Notice, that L and T now contain the first and second columns of data from the data file, ``pendulum.txt``, and they are both simple -sequences. ``unpack=True`` has given us the two columns in to two +sequences. ``unpack=True`` has given us the two columns into two separate sequences instead of one complex sequence. {{{ show the slide with loadtxt --- other features }}} diff --git a/manipulating-strings/script.rst b/manipulating-strings/script.rst index 50d5e32..c991dda 100644 --- a/manipulating-strings/script.rst +++ b/manipulating-strings/script.rst @@ -34,9 +34,6 @@ In this tutorial we shall learn to manipulate strings, specifically slicing and reversing them, or replacing characters, converting from upper to lower case and vice-versa and joining a list of strings. -.. #[punch: reversed returns an iterator. should we still teach it?] - - We have an ``ipython`` shell open, in which we are going to work, through out this session. @@ -69,9 +66,8 @@ the tutorial. So, we need to check if the first three characters of the given string exists in the variable ``week``. -As, with any of the string data-types, strings can be sliced into -.. #[Amit: Sequence data type???] -sub-strings. To get the first three characters of s, we say, +As, with any of the sequence data-types, strings can be sliced into +sub-strings. To get the first three characters of s, we say, :: @@ -84,7 +80,7 @@ As we already know, the last element of the string can be accessed using ``s[-1]``. Following is an exercise that you must do. -.. #[Amit: I don't know I am not sure about the sentence formation.] + %%1%% Obtain the sub-string excluding the first and last characters from the string s. @@ -129,7 +125,7 @@ So, we obtain the reverse of s, by simply saying, :: s[::-1] -.. #[amit: I think using reversed in not required after this] + Now, to check if the string is ``s`` is palindromic, we say :: @@ -152,16 +148,15 @@ Let's try it out. s +As you can see, s has not changed. It is because, ``upper`` returns a +new string. It doesn't change the original string. + +:: + s.lower() s.lower() == s.lower()[::-1] -Note that these methods, do not change the original string, but return -a new string. - -.. #[amit: I wish we could include this right when s.upper() is used so -.. that it is clear] - Following is an exercise that you must do. %%2%% Check if ``s`` is a valid name of a day of the week. Change the @@ -176,8 +171,11 @@ Please, pause the video here. Do the exercise and then continue. s.lower()[:3] in week -.. #[amit: May be a sentence or two about what our original problem was and -.. how this helps in solving it. One can loose the flow.] + +So, as you can see, now we can check for presence of ``s`` in +``week``, in whichever format it is present -- capitalized, or all +caps, full name or short form. + We just convert any input string to lower case and then check if it is present in the list ``week``. diff --git a/matrices/quickref.tex b/matrices/quickref.tex new file mode 100644 index 0000000..8e831bb --- /dev/null +++ b/matrices/quickref.tex @@ -0,0 +1,26 @@ +Matrix Multiplication:\\ +{\ex \lstinline| c = dot(a,b)|} + +Transpose of a matrix:\\ +{\ex \lstinline| m.T|} + +Inverse of a matrix:\\ +{\ex \lstinline| im = inv(m)|} + +Frobenius norm of matrix:\\ +{\ex \lstinline| norm(m)|} + +Inverse norm of matrix:\\ +{\ex \lstinline| norm(m, ord=inf)|} + +Determinant of matrix:\\ +{\ex \lstinline| det(m)|} + +Eigen values of matrix:\\ +{\ex \lstinline| eigvals(m)|} + +Eigen vectors of matrix:\\ +{\ex \lstinline| eig(m)[1]|} + +Singular Value Decomposition on matrix m:\\ +{\ex \lstinline| svd(m)|} diff --git a/matrices/script.rst b/matrices/script.rst index 646da8f..4e57f99 100644 --- a/matrices/script.rst +++ b/matrices/script.rst @@ -51,7 +51,7 @@ All matrix operations are done using arrays. Thus all the operations on arrays are valid on matrices also. A matrix may be created as, :: - m1 = matrix([1,2,3,4]) + m1 = array([1,2,3,4]) .. #[Puneeth: don't use ``matrix``. Use ``array``. The whole script will @@ -70,10 +70,16 @@ A list can be converted to a matrix as follows, :: l1 = [[1,2,3,4],[5,6,7,8]] - m2 = matrix(l1) + m2 = array(l1) -Note that all matrix operations are done using arrays, so a matrix may -also be created as +{{{ switch to next slide, exercise 1}}} + +Pause here and create a two dimensional matrix m3 of order 2 by 4 with +elements 5, 6, 7, 8, 9, 10, 11, 12. + +{{{ switch to next slide, solution }}} + +m3 can be created as, :: m3 = array([[5,6,7,8],[9,10,11,12]]) @@ -100,17 +106,16 @@ subtraction. Now let us try, m3 * m2 -Note that in arrays ``array(A) star array(B)`` does element wise -multiplication and not matrix multiplication, but unlike arrays, the -operation ``matrix(A) star matrix(B)`` does matrix multiplication and -not element wise multiplication. And in this case since the sizes are -not compatible for multiplication it returned an error. +Note that in arrays ``m3 * m2`` does element wise multiplication and not +matrix multiplication, -And element wise multiplication in matrices are done using the -function ``multiply()`` +And matrix multiplication in matrices are done using the function ``dot()`` :: - multiply(m3,m2) + dot(m3, m2) + +but due to size mismatch the multiplication could not be done and it +returned an error, {{{ switch to next slide, Matrix multiplication (cont'd) }}} @@ -126,11 +131,10 @@ matrix m1 is of the shape one by four, let us create another one of the order four by two, :: - m4 = matrix([[1,2],[3,4],[5,6],[7,8]]) - m1 * m4 + m4 = array([[1,2],[3,4],[5,6],[7,8]]) + dot(m1, m4) -thus unlike in array object ``star`` can be used for matrix multiplication -in matrix object. +thus the function ``dot()`` can be used for matrix multiplication. {{{ switch to next slide, recall from arrays }}} @@ -158,7 +162,7 @@ Now let us try to find out the Frobenius norm of inverse of a 4 by 4 matrix, the matrix being, :: - m5 = matrix(arange(1,17).reshape(4,4)) + m5 = arange(1,17).reshape(4,4) print m5 The inverse of a matrix A, A raise to minus one is also called the @@ -177,7 +181,7 @@ And the Frobenius norm of the matrix ``im5`` can be found out as, :: sum = 0 - for each in array(im5.flatten())[0]: + for each in im5.flatten(): sum += each * each print sqrt(sum) diff --git a/matrices/slides.org b/matrices/slides.org index 34caa29..b7f56f2 100644 --- a/matrices/slides.org +++ b/matrices/slides.org @@ -42,11 +42,16 @@ * Creating a matrix - Creating a matrix using direct data - : In []: m1 = matrix([1, 2, 3, 4]) + : In []: m1 = array([1, 2, 3, 4]) - Creating a matrix using lists : In []: l1 = [[1,2,3,4],[5,6,7,8]] - : In []: m2 = matrix(l1) - - A matrix is basically an array + : In []: m2 = array(l1) +* Exercise 1 + Create a (2, 4) matrix ~m3~ + : m3 = [[5, 6, 7, 8], + : [9, 10, 11, 12]] +* Solution 1 + - m3 can be created as, : In []: m3 = array([[5,6,7,8],[9,10,11,12]]) * Matrix operations @@ -55,20 +60,20 @@ - Element-wise subtraction (both matrix should be of order ~mXn~) : In []: m3 - m2 * Matrix Multiplication - - Matrix Multiplication + - Element-wise multiplication using ~m3 * m2~ : In []: m3 * m2 + - Matrix Multiplication using ~dot(m3, m2)~ + : In []: dot(m3, m2) : Out []: ValueError: objects are not aligned - - Element-wise multiplication using ~multiply()~ - : multiply(m3, m2) * Matrix Multiplication (cont'd) - Create two compatible matrices of order ~nXm~ and ~mXr~ : In []: m1.shape - matrix m1 is of order ~1 X 4~ - Creating another matrix of order ~4 X 2~ - : In []: m4 = matrix([[1,2],[3,4],[5,6],[7,8]]) + : In []: m4 = array([[1,2],[3,4],[5,6],[7,8]]) - Matrix multiplication - : In []: m1 * m4 + : In []: dot(m1, m4) * Recall from ~array~ - The functions - ~identity(n)~ - @@ -86,11 +91,11 @@ * More matrix operations Transpose of a matrix : In []: m4.T -* Exercise 1 : Frobenius norm \& inverse +* Exercise 2 : Frobenius norm \& inverse Find out the Frobenius norm of inverse of a ~4 X 4~ matrix. : The matrix is - : m5 = matrix(arange(1,17).reshape(4,4)) + : m5 = arange(1,17).reshape(4,4) - Inverse of A, - #+begin_latex @@ -102,7 +107,7 @@ $||A||_F = [\sum_{i,j} abs(a_{i,j})^2]^{1/2}$ #+end_latex -* Exercise 2: Infinity norm +* Exercise 3 : Infinity norm Find the infinity norm of the matrix ~im5~ : - Infinity norm is defined as, diff --git a/matrices/slides.tex b/matrices/slides.tex index 8e58583..e0e8acd 100644 --- a/matrices/slides.tex +++ b/matrices/slides.tex @@ -1,4 +1,4 @@ -% Created 2010-10-12 Tue 14:28 +% Created 2010-11-07 Sun 16:18 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -70,7 +70,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{itemize} \begin{verbatim} - In []: m1 = matrix([1, 2, 3, 4]) + In []: m1 = array([1, 2, 3, 4]) \end{verbatim} \begin{itemize} @@ -79,11 +79,25 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \begin{verbatim} In []: l1 = [[1,2,3,4],[5,6,7,8]] - In []: m2 = matrix(l1) + In []: m2 = array(l1) \end{verbatim} +\end{frame} +\begin{frame}[fragile] +\frametitle{Exercise 1} +\label{sec-3} + + Create a (2, 4) matrix \texttt{m3} +\begin{verbatim} + m3 = [[5, 6, 7, 8], + [9, 10, 11, 12]] +\end{verbatim} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 1} +\label{sec-4} \begin{itemize} -\item A matrix is basically an array +\item m3 can be created as, \end{itemize} \begin{verbatim} @@ -92,7 +106,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame}[fragile] \frametitle{Matrix operations} -\label{sec-3} +\label{sec-5} \begin{itemize} \item Element-wise addition (both matrix should be of order \texttt{mXn}) @@ -109,25 +123,25 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame}[fragile] \frametitle{Matrix Multiplication} -\label{sec-4} +\label{sec-6} \begin{itemize} -\item Matrix Multiplication +\item Element-wise multiplication using \texttt{m3 * m2} \begin{verbatim} In []: m3 * m2 - Out []: ValueError: objects are not aligned \end{verbatim} -\item Element-wise multiplication using \texttt{multiply()} +\item Matrix Multiplication using \texttt{dot(m3, m2)} \begin{verbatim} - multiply(m3, m2) + In []: dot(m3, m2) + Out []: ValueError: objects are not aligned \end{verbatim} \end{itemize} \end{frame} \begin{frame}[fragile] \frametitle{Matrix Multiplication (cont'd)} -\label{sec-5} +\label{sec-7} \begin{itemize} \item Create two compatible matrices of order \texttt{nXm} and \texttt{mXr} @@ -142,19 +156,19 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \item Creating another matrix of order \texttt{4 X 2} \begin{verbatim} - In []: m4 = matrix([[1,2],[3,4],[5,6],[7,8]]) + In []: m4 = array([[1,2],[3,4],[5,6],[7,8]]) \end{verbatim} \item Matrix multiplication \begin{verbatim} - In []: m1 * m4 + In []: dot(m1, m4) \end{verbatim} \end{itemize} \end{frame} \begin{frame} \frametitle{Recall from \texttt{array}} -\label{sec-6} +\label{sec-8} \begin{itemize} \item The functions @@ -178,7 +192,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame}[fragile] \frametitle{More matrix operations} -\label{sec-7} +\label{sec-9} Transpose of a matrix \begin{verbatim} @@ -186,8 +200,8 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{verbatim} \end{frame} \begin{frame}[fragile] -\frametitle{Exercise 1 : Frobenius norm \& inverse} -\label{sec-8} +\frametitle{Exercise 2 : Frobenius norm \& inverse} +\label{sec-10} Find out the Frobenius norm of inverse of a \texttt{4 X 4} matrix. \begin{verbatim} @@ -196,7 +210,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} The matrix is \begin{verbatim} - m5 = matrix(arange(1,17).reshape(4,4)) + m5 = arange(1,17).reshape(4,4) \end{verbatim} \begin{itemize} @@ -215,8 +229,8 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{itemize} \end{frame} \begin{frame}[fragile] -\frametitle{Exercise 2: Infinity norm} -\label{sec-9} +\frametitle{Exercise 3 : Infinity norm} +\label{sec-11} Find the infinity norm of the matrix \texttt{im5} \begin{verbatim} @@ -230,7 +244,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame}[fragile] \frametitle{\texttt{norm()} method} -\label{sec-10} +\label{sec-12} \begin{itemize} \item Frobenius norm @@ -247,7 +261,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame}[fragile] \frametitle{Determinant} -\label{sec-11} +\label{sec-13} Find out the determinant of the matrix m5 \begin{verbatim} @@ -265,7 +279,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame}[fragile] \frametitle{eigen values \& eigen vectors} -\label{sec-12} +\label{sec-14} Find out the eigen values and eigen vectors of the matrix \texttt{m5}. \begin{verbatim} @@ -300,7 +314,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame}[fragile] \frametitle{Singular Value Decomposition (\texttt{svd})} -\label{sec-13} +\label{sec-15} $M = U \Sigma V^*$ \begin{itemize} @@ -318,7 +332,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame} \frametitle{Summary} -\label{sec-14} +\label{sec-16} \begin{itemize} \item Matrices @@ -337,7 +351,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{frame} \begin{frame} \frametitle{Thank you!} -\label{sec-15} +\label{sec-17} \begin{block}{} \begin{center} diff --git a/other-type-of-plots/quickref.tex b/other-type-of-plots/quickref.tex new file mode 100644 index 0000000..275c226 --- /dev/null +++ b/other-type-of-plots/quickref.tex @@ -0,0 +1,11 @@ +Creating scatter plot:\\ +{\ex \lstinline| scatter(x, y)|} + +Creating pie chart:\\ +{\ex \lstinline| pie(p, labels=l)|} + +Creating bar chart:\\ +{\ex \lstinline| bar(x, y)|} + +Creating log-log chart:\\ +{\ex \lstinline| loglog(x, y)|} diff --git a/plotting-data/script.rst b/plotting-data/script.rst index 166256c..b338625 100644 --- a/plotting-data/script.rst +++ b/plotting-data/script.rst @@ -16,38 +16,50 @@ .. Author : Amit - Internal Reviewer : + Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in> External Reviewer : Checklist OK? : <put date stamp here, if OK> [2010-10-05] +.. #[[Anoop: Add quickref]] +.. #[[Anoop: Slides are incomplete, add summary slide, thank you slide + etc.]] + +=============================== Plotting Experimental Data -============================= -Hello and welcome , this tutorial on Plotting Experimental data is -presented by the fossee team. +=============================== {{{ Show the slide containing title }}} +Hello and welcome , this tutorial on Plotting Experimental data is +presented by the fossee team. {{{ Show the Outline Slide }}} +.. #[[Anoop: outline slide is missing]] + Here we will discuss plotting Experimental data. 1. We will see how we can represent a sequence of numbers in Python. -2. We will also become fimiliar with elementwise squaring of such a +2. We will also become familiar with elementwise squaring of such a sequence. 3. We will also see how we can use our graph to indicate Error. -One needs to be fimiliar with the concepts of plotting +One needs to be familiar with the concepts of plotting mathematical functions in Python. We will use data from a Simple Pendulum Experiment to illustrate our points. +.. #[[Anoop: what do you mean by points here? if you mean the + points/numbered list in outline slide, then remove the usage point + from here.]] + {{{ Simple Pendulum data Slide }}} - +.. #[[Anoop: slides are incomplete, work on slides and context + switches]] As we know for a simple pendulum length,L is directly proportional to @@ -59,14 +71,20 @@ of values. To tell ipython a sequence of values we write the sequence in comma seperated values inside two square brackets. This is also called List so to create two sequences -L,t type in ipython shell. :: +.. #[[Anoop: instead of saying "to tell ipython a sequence of values" + and make it complicated, we can tell, we define a sequence as]] + +L,t type in ipython shell. + +.. #[[Anoop: sentence is incomplete, can be removed]] + +:: In []: L = [0.1, 0.2, 0.3, 0.4, 0.5,0.6, 0.7, 0.8, 0.9] In []: t= [0.69, 0.90, 1.19,1.30, 1.47, 1.58, 1.77, 1.83, 1.94] - - + To obtain the square of sequence t we will use the function square with argument t.This is saved into the variable tsquare.:: @@ -75,10 +93,14 @@ with argument t.This is saved into the variable tsquare.:: array([ 0.4761, 0.81 , 1.4161, 1.69 , 2.1609, 2.4964, 3.1329, 3.3489, 3.7636]) +.. #[[Anoop: how do you get the array([ 0.4761 ....]) output?]] + Now to plot L vs T^2 we will simply type :: - In []: plot(L,t,.) + In []: plot(L,t,'.') + +.. #[[Anoop: be consistent with the spacing and all.]] '.' here represents to plot use small dots for the point. :: @@ -86,17 +108,26 @@ Now to plot L vs T^2 we will simply type :: You can also specify 'o' for big dots.:: - In []: plot(L,t,o) + In []: plot(L,t,'o') In []: clf() +.. #[[Anoop: Make sure code is correct, corrected plot(L,t,o) to + plot(L,t,'o')]] + {{{ Slide with Error data included }}} +.. #[[Anoop: again slides are incomplete.]] Now we shall try and take into account error into our plots . The Error values for L and T are on your screen.We shall again intialize -the sequence values in the same manner as we did for L and t :: +the sequence values in the same manner as we did for L and t + +.. #[[Anoop: give introduction to error and say what we are going to + do]] + +:: In []: delta_L= [0.08,0.09,0.07,0.05,0.06,0.00,0.06,0.06,0.01] @@ -111,10 +142,12 @@ The syntax of the command is as given on the screen. :: In []: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.') -This gives a plot with error bar for x and y axis. The dots are of blue color. The parameters xerr and yerr are error on x and y axis and fmt is the format of the plot. +This gives a plot with error bar for x and y axis. The dots are of +blue color. The parameters xerr and yerr are error on x and y axis and +fmt is the format of the plot. -similarly we can draw the same error bar with big red dots just change +similarly we can draw the same error bar with big red dots just change the parameters to fmt to 'ro'. :: In []: clf() @@ -143,7 +176,7 @@ In this tutorial we have learnt : {{{ Show the "sponsored by FOSSEE" slide }}} - +.. #[[Anoop: again slides are incomplete]] This tutorial was created as a part of FOSSEE project. @@ -151,8 +184,3 @@ Hope you have enjoyed and found it useful. Thankyou - - -Author : Amit Sethi -Internal Reviewer : -Internal Reviewer 2 : diff --git a/plotting-data/slides.tex b/plotting-data/slides.tex index 1957418..bb7c4ee 100644 --- a/plotting-data/slides.tex +++ b/plotting-data/slides.tex @@ -1,21 +1,28 @@ -% Created 2010-10-28 Thu 15:05 +% Created 2010-11-07 Sun 18:57 \documentclass[presentation]{beamer} -\usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} +\usepackage{fixltx2e} \usepackage{graphicx} \usepackage{longtable} \usepackage{float} \usepackage{wrapfig} \usepackage{soul} +\usepackage{t1enc} +\usepackage{textcomp} +\usepackage{marvosym} +\usepackage{wasysym} +\usepackage{latexsym} \usepackage{amssymb} \usepackage{hyperref} - +\tolerance=1000 +\providecommand{\alert}[1]{\textbf{#1}} \title{Plotting Experimental Data} \author{FOSSEE} \date{2010-09-14 Tue} +\usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} \begin{document} \maketitle @@ -31,7 +38,7 @@ \begin{itemize} \item Plotting Experiment Data and Error Bars\\ -\label{sec-1.1}% +\label{sec-1_1}% \end{itemize} % ends low level \end{frame} \begin{frame} @@ -40,7 +47,7 @@ \begin{itemize} \item Plotting simple analytical Functions\\ -\label{sec-2.1}% +\label{sec-2_1}% \end{itemize} % ends low level \end{frame} \begin{frame} diff --git a/progress.org b/progress.org index 2c7ec66..91c747e 100644 --- a/progress.org +++ b/progress.org @@ -1,55 +1,56 @@ -| S.No | Name | Units | Author | Review | Checklist | -|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| -| 1.2 LO: | getting started with =ipython= | 2 | Punch | Anoop(Done) | | -| 1.3 LO: | using the =plot= command interactively | 2 | Amit | Pending | | -| 1.4 LO: | embellishing a plot | 2 | Nishanth | Anoop (Done) | | -| 1.5 LO: | saving plots | 2 | Anoop | Punch (Done) | | -| 1.6 LO: | multiple plots | 3 | Madhu | Nishanth (Done) | | -| 1.7 LO: | additional features of IPython | 2 | Nishanth | Amit (Pending) | | -| 1.8 LO: | module level assessment | 3 | Madhu | | | -|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| -| 2.2 LO: | loading data from files | 3 | Punch | Nishanth (Done) | | -| 2.3 LO: | plotting the data | 3 | Amit | Pending | | -| 2.4 LO: | other types of plots | 3 | Anoop | Punch (Done) | | -| 2.5 LO: | module level assessment | 3 | Nishanth | | | -|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| -| 3.1 LO: | getting started with lists | 2 | Amit | Pending | | -| 3.2 LO: | getting started with =for= | 2 | Anoop | Nishanth (Done) | | -| 3.3 LO: | getting started with strings | 2 | Madhu | | | -| 3.4 LO: | getting started with files | 3 | Punch | Anoop(Done) | | -| 3.5 LO: | parsing data | 3 | Nishanth | Amit (Done) | | -| 3.6 LO: | statistics | 2 | Amit | Pending | | -| 3.7 LO: | module level assessment | 3 | Madhu | | | -|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| -| 4.1 LO: | getting started with arrays | 2 | Anoop | Punch (Done) | | -| 4.2 LO: | accessing parts of arrays | 4 | Punch | Anoop(Done) | | -| 4.3 LO: | Matrices | 3 | Anoop | Punch (changes before further review) | | -| 4.4 LO: | Least square fit | 2 | Nishanth | Punch (Done) | | -| 4.5 LO: | Assessment | 3 | Punch | | | -|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| -| 5.1 LO: | getting started with sage notebook | 3 | Madhu | | | -| 5.2 LO: | getting started with symbolics | 3 | Amit | Pending | | -| 5.3 LO: | using Sage | 4 | Punch | Anoop (Done) | | -| 5.4 LO: | using sage to teach | 3 | Nishanth | | | -| 5.5 LO: | Assessment | 3 | Anoop | | | -|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| -| 6.1 LO: | basic datatypes & operators | 4 | Amit | Punch (Done) | | -| 6.2 LO: | I/O | 1 | Nishanth | | | -| 6.3 LO: | conditionals | 2 | Madhu | | | -| 6.4 LO: | loops | 2 | Puneeth | Anoop(Done) | | -| 6.5 LO: | Assessment | 3 | Anoop | | | -|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| -| 7.1 LO: | manipulating lists | 3 | Madhu | | | -| 7.2 LO: | manipulating strings | 2 | Punch | Amit(Done) | | -| 7.3 LO: | getting started with tuples | 2 | Nishanth | | | -| 7.4 LO: | dictionaries | 2 | Anoop | Punch (Done) | | -| 7.5 LO: | sets | 2 | Nishanth | | | -| 7.6 LO: | Assessment | 3 | Amit | | | -|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| -| 8.1 LO: | getting started with functions | 3 | Nishanth | | | -| 8.2 LO: | advanced features of functions | 3 | Punch | Anoop(Done) | | -| 8.3 LO: | using python modules | 3 | Anoop | Punch (Done) | | -| 8.4 LO: | writing python scripts | 2 | Nishanth | | | -| 8.5 LO: | testing and debugging | 2 | Amit | | | -| 8.6 LO: | Assessment | 3 | Madhu | | | -|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| +| S.No | Name | Units | Author | Review | Checklist | +|---------+----------------------------------------+-------+----------+-------------------------------------+-----------| +| 1.2 LO: | getting started with =ipython= | 2 | Punch | Anoop(Done) | | +| 1.3 LO: | using the =plot= command interactively | 2 | Amit | Pending | | +| 1.4 LO: | embellishing a plot | 2 | Nishanth | Anoop (Done) | | +| 1.5 LO: | saving plots | 2 | Anoop | Punch (Done) | | +| 1.6 LO: | multiple plots | 3 | Madhu | Nishanth (Done) | | +| 1.7 LO: | additional features of IPython | 2 | Nishanth | Amit (Pending) | | +| 1.8 LO: | module level assessment | 3 | Madhu | | | +|---------+----------------------------------------+-------+----------+-------------------------------------+-----------| +| 2.2 LO: | loading data from files | 3 | Punch | Nishanth (Done) | | +| 2.3 LO: | plotting the data | 3 | Amit | Pending | | +| 2.4 LO: | other types of plots | 3 | Anoop | Punch (Done) | | +| 2.5 LO: | module level assessment | 3 | Nishanth | | | +|---------+----------------------------------------+-------+----------+-------------------------------------+-----------| +| 3.1 LO: | getting started with lists | 2 | Amit | Pending | | +| 3.2 LO: | getting started with =for= | 2 | Anoop | Nishanth (Done) | | +| 3.3 LO: | getting started with strings | 2 | Madhu | | | +| 3.4 LO: | getting started with files | 3 | Punch | Anoop(Done) | | +| 3.5 LO: | parsing data | 3 | Nishanth | Amit (Done) | | +| 3.6 LO: | statistics | 2 | Amit | Punch (Done) | | +| 3.7 LO: | module level assessment | 3 | Madhu | | | +|---------+----------------------------------------+-------+----------+-------------------------------------+-----------| +| 4.1 LO: | getting started with arrays | 2 | Anoop | Punch (Done) | | +| 4.2 LO: | accessing parts of arrays | 4 | Punch | Anoop (Done) | | +| 4.3 LO: | Matrices | 3 | Anoop | Punch (changes made, please review) | | +| 4.4 LO: | Least square fit | 2 | Nishanth | Punch (Done) | | +| 4.5 LO: | Assessment | 3 | Punch | | | +|---------+----------------------------------------+-------+----------+-------------------------------------+-----------| +| 5.1 LO: | getting started with sage notebook | 3 | Madhu | | | +| 5.2 LO: | getting started with symbolics | 3 | Amit | Pending | | +| 5.3 LO: | using Sage | 4 | Punch | Anoop (Done) | | +| 5.4 LO: | using sage to teach | 3 | Nishanth | | | +| 5.5 LO: | Assessment | 3 | Anoop | | | +|---------+----------------------------------------+-------+----------+-------------------------------------+-----------| +| 6.1 LO: | basic datatypes & operators | 4 | Amit | Punch (Done) | | +| 6.2 LO: | I/O | 1 | Nishanth | | | +| 6.3 LO: | conditionals | 2 | Madhu | | | +| 6.4 LO: | loops | 2 | Punch | Anoop (Done) | | +| 6.5 LO: | Assessment | 3 | Anoop | | | +|---------+----------------------------------------+-------+----------+-------------------------------------+-----------| +| 7.1 LO: | manipulating lists | 3 | Madhu | | | +| 7.2 LO: | manipulating strings | 2 | Punch | Amit(Done) | | +| 7.3 LO: | getting started with tuples | 2 | Nishanth | | | +| 7.4 LO: | dictionaries | 2 | Anoop | Punch (Done) | | +| 7.5 LO: | sets | 2 | Nishanth | | | +| 7.6 LO: | Assessment | 3 | Amit | | | +|---------+----------------------------------------+-------+----------+-------------------------------------+-----------| +| 8.1 LO: | getting started with functions | 3 | Nishanth | | | +| 8.2 LO: | advanced features of functions | 3 | Punch | Anoop (Done) | | +| 8.3 LO: | using python modules | 3 | Anoop | Punch (Done) | | +| 8.4 LO: | writing python scripts | 2 | Nishanth | | | +| 8.5 LO: | testing and debugging | 2 | Amit | | | +| 8.6 LO: | Assessment | 3 | Madhu | | | +|---------+----------------------------------------+-------+----------+-------------------------------------+-----------| + diff --git a/savefig/quickref.tex b/savefig/quickref.tex new file mode 100644 index 0000000..e485ae0 --- /dev/null +++ b/savefig/quickref.tex @@ -0,0 +1,5 @@ +Saving a plot(png):\\ +{\ex \lstinline| savefig('filename.png')|} + +Saving a plot(pdf):\\ +{\ex \lstinline| savefig('filename.pdf')|} diff --git a/statistics/script.rst b/statistics/script.rst index e8694be..5523fce 100644 --- a/statistics/script.rst +++ b/statistics/script.rst @@ -19,7 +19,9 @@ External Reviewer : Checklist OK? : <put date stamp here, if OK> [2010-10-05] -Hello friends and welcome to the tutorial on statistics using Python +.. #[punch; add slides, exercises!] + +Hello friends and welcome to the tutorial on Statistics using Python {{{ Show the slide containing title }}} @@ -29,57 +31,78 @@ In this tutorial, we shall learn * Doing simple statistical operations in Python * Applying these to real world problems -You will need Ipython with pylab running on your computer -to use this tutorial. +.. #[punch: the prerequisites part may be skipped in the tutorial. It +.. will be provided separately.] + +You will need Ipython with pylab running on your computer to use this +tutorial. + +Also you will need to know about loading data using loadtxt to be able +to follow the real world application. + +.. #[punch: since loadtxt is anyway a pre-req, I would recommend you +.. to use a data file and load data from that. that is good, since you +.. would get to deal with arrays, instead of lists. + +.. Talking of rows and columns of 2-D lists etc is confusing. Also, +.. converting to float can be avoided. The tutorial will feel more +.. natural, is what I think. -Also you will need to know about loading data using loadtxt to be -able to follow the real world application. +.. The idea of separating the main problem and giving toy examples +.. doesn't sound good. Use the same problem to explain stuff. Or use a +.. smaller data-set or something. Using lists doesn't seem natural.] -We will first start with the most necessary statistical -operation i.e finding mean. + +We will first start with the most necessary statistical operation i.e +finding mean. We have a list of ages of a random group of people :: - age_list=[4,45,23,34,34,38,65,42,32,7] + age_list = [4,45,23,34,34,38,65,42,32,7] -One way of getting the mean could be getting sum of -all the elements and dividing by length of the list.:: +One way of getting the mean could be getting sum of all the ages and +dividing by the number of people in the group. :: - sum_age_list =sum(age_list) + sum_age_list = sum(age_list) -sum function gives us the sum of the elements.:: +sum function gives us the sum of the elements. Note that the +``sum_age_list`` variable is an integer and the number of people or +length of the list is also an integer. We will need to convert one of +them to a float before carrying out the division. :: - mean_using_sum=float(sum_age_list)/len(age_list) + mean_using_sum = float(sum_age_list)/len(age_list) -This obviously gives the mean age but python has another -method for getting the mean. This is the mean function:: +This obviously gives the mean age but there is a simpler way to do +this in Python - using the mean function:: mean(age_list) -Mean can be used in more ways in case of 2 dimensional lists. -Take a two dimensional list :: +Mean can be used in more ways in case of 2 dimensional lists. Take a +two dimensional list :: two_dimension=[[1,5,6,8],[1,3,4,5]] -the mean function used in default manner will give the mean of the -flattened sequence. Flattened sequence means the two lists taken -as if it was a single list of elements :: +The mean function by default gives the mean of the flattened sequence. +A Flattened sequence means a list obtained by concatenating all the +smaller lists into a large long list. In this case, the list obtained +by writing the two lists one after the other. :: mean(two_dimension) flattened_seq=[1,5,6,8,1,3,4,5] mean(flattened_seq) -As you can see both the results are same. The other way is mean -of each column.:: +As you can see both the results are same. ``mean`` function can also +give us the mean of each column, or the mean of corresponding elements +in the smaller lists. :: - mean(two_dimension,0) + mean(two_dimension, 0) array([ 1. , 4. , 5. , 6.5]) we pass an extra argument 0 in that case. -In case of getting mean along the rows the argument is 1:: +If we use an argument 1, we obtain the mean along the rows. :: - mean(two_dimension,1) + mean(two_dimension, 1) array([ 5. , 3.25]) We can see more option of mean using :: @@ -92,24 +115,26 @@ using the functions median and std:: median(age_list) std(age_list) -Median and std can also be calculated for two dimensional arrays along columns and rows just like mean. +Median and std can also be calculated for two dimensional arrays along +columns and rows just like mean. - For example :: +For example :: - median(two_dimension,0) - std(two_dimension,1) + median(two_dimension, 0) + std(two_dimension, 1) -This gives us the median along the colums and standard devition along the rows. +This gives us the median along the colums and standard devition along +the rows. Now lets apply this to a real world example -We will a data file that is at the a path -``/home/fossee/sslc2.txt``.It contains record of students and their -performance in one of the State Secondary Board Examination. It has -180, 000 lines of record. We are going to read it and process this -data. We can see the content of file by double clicking on it. It -might take some time to open since it is quite a large file. Please -don't edit the data. This file has a particular structure. +We will a data file that is at the a path ``/home/fossee/sslc2.txt``. +It contains record of students and their performance in one of the +State Secondary Board Examination. It has 180, 000 lines of record. We +are going to read it and process this data. We can see the content of +file by double clicking on it. It might take some time to open since +it is quite a large file. Please don't edit the data. This file has +a particular structure. We can do :: @@ -128,7 +153,7 @@ The following are the fields in any given line. * Marks of 5 subjects: ** English 083 ** Hindi 042 ** Maths 47 ** Science 35 ** Social 72 * Total marks 244 -* + Now lets try and find the mean of English marks of all students. @@ -145,11 +170,11 @@ because usecols is a sequence. To get the median marks. :: - median(L) + median(L) Standard deviation. :: - std(L) + std(L) Now lets try and and get the mean for all the subjects :: @@ -187,10 +212,5 @@ This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India Hope you have enjoyed and found it useful. -Thankyou - -.. Author : Amit Sethi - Internal Reviewer 1 : - Internal Reviewer 2 : - External Reviewer : +Thank you! diff --git a/using python modules/quickref.tex b/using python modules/quickref.tex new file mode 100644 index 0000000..cfa992a --- /dev/null +++ b/using python modules/quickref.tex @@ -0,0 +1,16 @@ +Import all definitions to current name-space:\\ +{\ex \lstinline| from scipy import *|} + +Import few definitions to current name-space:\\ +{\ex \lstinline| from scipy import linspace, pi, sin|} + +Import a module as a new name-space:\\ +{\ex \lstinline| import scipy|} + +Few standard python modules:\\ +{\ex \lstinline| Math: math, random|} +{\ex \lstinline| Internet: urllib2, smtplib|} +{\ex \lstinline| System: sys|} +{\ex \lstinline| OS: os|} +{\ex \lstinline| Regular Expression: re|} +{\ex \lstinline| Compression: gzip, zipfile, tarfile|} diff --git a/using-sage/script.rst b/using-sage/script.rst index 918dacc..21c6af2 100644 --- a/using-sage/script.rst +++ b/using-sage/script.rst @@ -16,7 +16,8 @@ .. Author : Puneeth Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in> External Reviewer : - Checklist OK? : <put date stamp here, if OK> [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <06-11-2010, Anand, OK> [2010-10-05] Script ------ |