From dc863a469939d03140bc93df083edebd7e8f9cf6 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 26 Oct 2010 11:13:32 +0530 Subject: Reviewed savefig script. --- savefig/script.rst | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/savefig/script.rst b/savefig/script.rst index b2068cc..87bcfe6 100644 --- a/savefig/script.rst +++ b/savefig/script.rst @@ -3,8 +3,8 @@ .. At the end of this tutorial, you will be able to -.. 1. Saving plots using ``savefig()`` function. -.. #. Saving plots in different formats. +.. 1. Save plots using ``savefig()`` function. +.. #. Save plots in different formats. .. Prerequisites @@ -19,6 +19,7 @@ External Reviewer : Checklist OK? : [2010-10-05] +.. #[Puneeth: Quickref missing.] ======= Savefig @@ -30,8 +31,10 @@ Hello and welcome to the tutorial saving plots. {{{ switch to next slide, outline slide }}} -In this tutorial you will learn how to save plots using Python. And -saving in different formats, and locating the file in the file system. +In this tutorial you will learn how to save plots using Python, saving +in different formats, and locating the file in the file system. + +.. #[Puneeth: file-system is too technical.] {{{ switch to next slide, a sine wave}}} @@ -39,8 +42,8 @@ Start your IPython interpreter with the command :: ipython -pylab -It will start your IPython interpreter with the required python -modules for plotting and saving your plots. +As you know, it will start your IPython interpreter with the required +python modules for plotting and saving your plots. {{{ Open ipython }}} @@ -61,6 +64,10 @@ Done! we have made a very basic sine plot, now let us see how to save the plot for future use so that you can embed the plot in your reports. +.. #[Puneeth: All this is known stuff. You don't have to elaborate so +.. much on it. Just say, let us plot sin function from -3 pi to 3 +.. pi. Show the commands, and be done with it. ] + {{{ switch to next slide, savefig() }}} {{{ Switch the focus to IPython interpreter window }}} @@ -70,10 +77,12 @@ done with the plot window open. The statement is, :: savefig('/home/fossee/sine.png') -Notice that ``savefig`` function takes one argument which is a string -which is the filename. The last 3 characters after the ``.`` in the -filename is the extension or type of the file which determines the -format in which you want to save. +Notice that ``savefig`` function takes one argument which is the +filename. The last 3 characters after the ``.`` in the filename is the +extension or type of the file which determines the format in which you +want to save. + +.. #[Puneeth: removed mention of string] {{{ Highlight the /home/fossee part using mouse movements }}} -- cgit From 09bc218715a412690c4881dd3f3e8a2f4958d69e Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 26 Oct 2010 14:50:33 +0530 Subject: Reviewed other types of plots. --- other-type-of-plots/script.rst | 31 ++++++++++++++++++++++++------- progress.org | 4 ++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/other-type-of-plots/script.rst b/other-type-of-plots/script.rst index 9664dd0..4bb5480 100644 --- a/other-type-of-plots/script.rst +++ b/other-type-of-plots/script.rst @@ -22,6 +22,7 @@ External Reviewer : Checklist OK? : [2010-10-05] +.. #[Puneeth: Quickref missing] =================== Other type of plots @@ -31,12 +32,21 @@ Other type of plots Hello and welcome to the tutorial other type of plots. +.. #[Puneeth: this sentence doesn't read well] + {{{ show the outline slide }}} +.. #[Puneeth: motivate looking at other plots. Why are we looking at +.. them? Tell that we have only looked at one type of plot all the +.. while, etc.] + In this tutorial we will cover scatter plot, pie chart, bar chart and -loglog plot. We will also see few other plots and also introduce you to +log-log plot. We will also see few other plots and also introduce you to the matplotlib help. +.. #[Puneeth: cover, see and introduce you. be consistent. does, the +.. "We" include the viewer or not?] + Let us start with scatter plot. {{{ switch to the next slide, scatter plot }}} @@ -47,8 +57,7 @@ horizontal axis and the value of the other variable determining the position on the vertical axis. This kind of plot is also called a scatter chart, scatter diagram and scatter graph. -Before we proceed further get your IPython interpreter running with -the ``-pylab`` option. Start your IPython interpreter as +Before we proceed further, start your IPython interpreter :: ipython -pylab @@ -59,9 +68,9 @@ ipython -pylab }}} {{{ switch to the next slide having the problem statement of first exercise }}} -Now, let us plot a scatter plot showing the percentage profit of company A -from the year 2000-2010. The data for the same is available in the -file ``company-a-data.txt``. +Now, let us plot a scatter plot showing the percentage profit of +company A from the year 2000-2010. The data for the same is available +in the file ``company-a-data.txt``. {{{ open the file company-a-data.txt and show the content }}} @@ -78,6 +87,9 @@ and it can be done as :: year,profit = loadtxt('/home/fossee/other-plot/company-a-data.txt',dtype=type(int())) +.. #[Puneeth: make a remark about dtype, that has not been covered in +.. the loadtxt tutorial.] + {{{ switch to next slide, ``scatter`` function }}} Now in-order to generate the scatter graph we will use the function @@ -104,6 +116,9 @@ Pause here and solve the question before moving on. Now let us move on to pie chart. +.. #[Puneeth: instead of just saying that, say that let's plot a pie +.. chart for the same data. continuity, will be good.] + {{{ switch to the slide which says about pie chart }}} A pie chart or a circle graph is a circular chart divided into @@ -116,6 +131,8 @@ Plot a pie chart representing the profit percentage of company A, with the same data from file ``company-a-data.txt``. So let us reuse the data we have loaded from the file previously. +.. #[Puneeth, this part can be move above.] + {{{ switch to next slide, ``pie()`` function }}} We can plot the pie chart using the function ``pie()``. @@ -192,7 +209,7 @@ exercise question }}} Plot a `log-log` chart of y=5*x\ :sup:`3` for x from 1-20. Before we actually plot let us calculate the points needed for -that. And it could be done as, +that. :: x = linspace(1,20,100) diff --git a/progress.org b/progress.org index 77573e4..9c07b9e 100644 --- a/progress.org +++ b/progress.org @@ -3,14 +3,14 @@ | 1.2 LO: | getting started with =ipython= | 2 | Punch | Pending | | | 1.3 LO: | using the =plot= command interactively | 2 | Amit | | | | 1.4 LO: | embellishing a plot | 2 | Nishanth | Anoop (Done) | | -| 1.5 LO: | saving plots | 2 | Anoop | | | +| 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 | | | -| 2.4 LO: | other types of plots | 3 | Anoop | 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 | | | -- cgit From 8d92700e2cff705b775093e7d3d668b5e713a4e9 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 26 Oct 2010 20:54:21 +0530 Subject: Reviewed dictionaries script. --- dictionaries/script.rst | 20 +++++++++++--------- progress.org | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/dictionaries/script.rst b/dictionaries/script.rst index 1f5d102..c3539f6 100644 --- a/dictionaries/script.rst +++ b/dictionaries/script.rst @@ -6,9 +6,9 @@ .. 1. Create dictionaries .. #. Add data to dictionaries .. #. Retrieve data -.. #. Familiarize using ``.keys()`` and ``.values()`` methods -.. #. Checking for container-ship of keys -.. #. Iterating over elements +.. #. use ``.keys()`` and ``.values()`` methods +.. #. Check for container-ship of keys +.. #. Iterate over elements .. Prerequisites .. ------------- @@ -22,6 +22,7 @@ External Reviewer : Checklist OK? : [2010-10-05] +.. #[Puneeth: Quickref] ============ Dictionaries @@ -49,6 +50,8 @@ indexes, dictionaries have keys or strings as indexes. Before we can proceed, start your IPython interpreter with the ``-pylab`` option. +.. #[Puneeth: We don't need pylab] + {{{ start ipython interpreter by issuing command ipython -pylab }}} {{{ switch to next slide, Creating dictionary }}} @@ -59,11 +62,11 @@ your IPython interpreter. mt_dict = {} -Notice that unlike lists curly braces are used define ``dictionary``, +Notice that unlike lists, curly braces are used define ``dictionary``. {{{ move the mouse over curly braces to grab attention }}} -Now let us see how to create a filled dictionary, +Now let us see how to create a non-empty dictionary, :: extensions = {'jpg' : 'JPEG Image', 'py' : 'Python script', 'html' : 'Html document', 'pdf' : 'Portable Document Format'} @@ -146,10 +149,9 @@ dictionary. For that we can use ``in``, 'py' in extensions 'odt' in extensions -So in short it will return ``True`` if the key is found in the -dictionary, and will return ``False`` if key is not present. Note that -we can check only for container-ship of keys in dictionaries and not -values. +It will return ``True`` if the key is found in the dictionary, and +will return ``False`` if key is not present. Note that we can check +only for container-ship of keys in dictionaries and not values. {{{ switch to next slide, Retrieve keys and values }}} diff --git a/progress.org b/progress.org index 9c07b9e..22535cc 100644 --- a/progress.org +++ b/progress.org @@ -42,13 +42,13 @@ | 7.1 LO: | manipulating lists | 3 | Madhu | | | | 7.2 LO: | manipulating strings | 2 | Punch | Pending | | | 7.3 LO: | getting started with tuples | 2 | Nishanth | | | -| 7.4 LO: | dictionaries | 2 | Anoop | Pending | | +| 7.4 LO: | dictionaries | 2 | Anoop | Punch (Pending) | | | 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 | Pending | | -| 8.3 LO: | using python modules | 3 | Anoop | Pending | | +| 8.3 LO: | using python modules | 3 | Anoop | Punch (Pending) | | | 8.4 LO: | writing python scripts | 2 | Nishanth | | | | 8.5 LO: | testing and debugging | 2 | Amit | | | | 8.6 LO: | Assessment | 3 | Madhu | | | -- cgit From d221a44a093dc366a65afdde7b1cfdbb074b25f9 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Wed, 27 Oct 2010 12:50:10 +0530 Subject: Reviewed using python modules LO. --- using python modules/script.rst | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/using python modules/script.rst b/using python modules/script.rst index e3190fd..c7103f6 100644 --- a/using python modules/script.rst +++ b/using python modules/script.rst @@ -36,6 +36,8 @@ In this tutorial, we will see how to run python scripts from command line, importing modules, importing scipy and pylab modules. And also see the Python standard library. +.. #[Punch: the sentence seems discontinuous.] + {{{ switch to next slide on executing python scripts from command line }}} Let us create a simple python script to print hello world. Open your @@ -121,8 +123,8 @@ Now let us run the script again, python four_plot.py -Now it gave another error plot not defined, let us edit the file again -and add the line below the line we just added, +Now it gave another error -- plot not defined, let us edit the file +again and add the line below the line we just added, {{{ switch to next slide, fix ``plot`` problem }}} @@ -154,7 +156,7 @@ instead of, from scipy import * So in practice it is always good to use function names instead of -asterisk or star. As if we use asterisk to import from a particular +asterisk or star. If we use asterisk to import from a particular module then it will replace any existing functions with the same name in our name-space. @@ -208,8 +210,8 @@ We can run it as, {{{ switch to next slide, What is a module? }}} -So till now we have been learning about importing modules, now what is -a module? +Until now we have been learning about importing modules, now what is a +module? A module is simply a file containing Python definitions and statements. Definitions from a module can be imported into other @@ -217,10 +219,9 @@ modules or into the main module. {{{ switch to next slide, Python standard library }}} -Python has a very rich standard library of modules - -Python's standard library is very extensive, offering a wide range of -facilities. Some of the standard modules are, +Python has a very rich standard library of modules. It is very +extensive, offering a wide range of facilities. Some of the standard +modules are, for Math: math, random for Internet access: urllib2, smtplib -- cgit From 43d31cd72a882e8b9460a5b05665a057437eae60 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Wed, 27 Oct 2010 12:53:46 +0530 Subject: Merged heads. --- accessing-pieces-arrays/script.rst | 36 ++++++++++++++++++++++++++++++- accessing-pieces-arrays/slides.tex | 43 ++++++++++++++++---------------------- getting-started-ipython/script.rst | 23 ++++++++++++++++++-- getting-started-ipython/slides.tex | 3 ++- manipulating-strings/script.rst | 15 +++++++++---- 5 files changed, 87 insertions(+), 33 deletions(-) diff --git a/accessing-pieces-arrays/script.rst b/accessing-pieces-arrays/script.rst index 8e08146..5c60750 100644 --- a/accessing-pieces-arrays/script.rst +++ b/accessing-pieces-arrays/script.rst @@ -37,6 +37,8 @@ slicing and striding. {{{ switch back to the terminal }}} +.. #[[Anoop: context switch, switch to next slide should be added]] + As usual, we start IPython, using :: @@ -66,7 +68,9 @@ To access, the element 34 in A, we say, :: - A[1] + A[2] + +.. #[[Anoop: should be A[2], corrected it]] Like lists, indexing starts from 0 in arrays, too. So, 34, the third element has the index 2. @@ -130,6 +134,8 @@ column by Following is an exercise that you must do. +.. #[[Anoop: add context switches, switch to next slide]] + %%1%% Change the last column of C to zeroes. Please, pause the video here. Do the exercises and then continue. @@ -148,6 +154,8 @@ gives the whole of A. Following is an exercise that you must do. +.. #[[Anoop: add context switches, switch to next slide]] + %%2%% Change ``A`` to ``[11, 12, 13, 14, 15]``. Please, pause the video here. Do the exercises and then continue. @@ -194,6 +202,10 @@ at the prompt, and see that an array is displayed. To check the dimensions of any array, we can use the method shape. We say + +.. #[[Anoop: method is a function and .shape is a tuple, so it can be named + as value or something instead of the term method.]] + :: I.shape @@ -230,12 +242,16 @@ columns indexed 0 to 2 (included), we say, Following is an exercise that you must do. +.. #[[Anoop: add context switches, switch to next slide]] + %%3%% First, obtain the elements [22, 23] from C. Then, obtain the elements [11, 21, 31, 41] from C. Finally, obtain the elements [21, 31, 41, 0]. Please, pause the video here. Do the exercises and then continue. +.. #[[Anoop: add context switches, switch to next slide]] + :: C[1, 1:3] @@ -270,10 +286,14 @@ we get the slice from end to end, as we already know. Following is an exercise that you must do. +.. #[[Anoop: add context switches, switch to next slide]] + %%4%% Obtain the elements [[23, 24], [33, -34]] from C. Please, pause the video here. Do the exercises and then continue. +.. #[[Anoop: add context switches, switch to next slide]] + :: C[1:3, 2:4] @@ -298,10 +318,14 @@ form of an image and confirm. Following is an exercise that you must do. +.. #[[Anoop: add context switches, switch to next slide]] + %%5%% Obtain the square in the center of the image. Following is an exercise that you must do. +.. #[[Anoop: add context switches, switch to next slide]] + :: imshow(I[75:225, 75:225]) @@ -335,6 +359,10 @@ of 1 is assumed. gives the elements, [[21, 23, 0], [41, 43, 0]] +.. #[[Anoop: I think you forgot to "add switch to next slide" context + switch, I think it will be better you review the scripts(all) for + context switches and add them.]] + Following is an exercise that you must do. %%6%% Obtain the following. @@ -382,6 +410,12 @@ elements, rows and columns and larger pieces of arrays. We have also learnt how to modify arrays, element wise or in larger pieces. +.. #[[Anoop: I think in the summary slide it is better to use single & + multi dimensional arrays instead of 1D and Multi dimensional arrays.]] + +.. #[[Anoop: switch to thank you slide, added comment as it most probably + won't be noticed]] + Thank You! .. diff --git a/accessing-pieces-arrays/slides.tex b/accessing-pieces-arrays/slides.tex index 019260b..8a0f1a9 100644 --- a/accessing-pieces-arrays/slides.tex +++ b/accessing-pieces-arrays/slides.tex @@ -1,4 +1,4 @@ -% Created 2010-10-10 Sun 18:48 +% Created 2010-10-26 Tue 12:11 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -8,6 +8,7 @@ \usepackage{float} \usepackage{wrapfig} \usepackage{soul} +\usepackage{t1enc} \usepackage{textcomp} \usepackage{marvosym} \usepackage{wasysym} @@ -56,8 +57,7 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \frametitle{Sample Arrays} \label{sec-2} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} 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{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Question 1} @@ -77,10 +77,9 @@ In []: C = array([[11, 12, 13, 14, 15], \frametitle{Solution 1} \label{sec-4} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} In []: C[:, -1] = 0 -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Question 2} @@ -92,10 +91,9 @@ In []: C[:, -1] = 0 \frametitle{Solution 2} \label{sec-6} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} In []: A[:] = [11, 12, 13, 14, 15] -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{squares.png} @@ -119,12 +117,11 @@ In []: A[:] = [11, 12, 13, 14, 15] \frametitle{Solution 3} \label{sec-9} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} In []: C[1, 1:3] In []: C[0:4, 0] In []: C[1:5, 0] -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Question 4} @@ -136,10 +133,9 @@ In []: C[1:5, 0] \frametitle{Solution 4} \label{sec-11} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} In []: C[1:3, 2:4] -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Question 5} @@ -151,31 +147,28 @@ In []: C[1:3, 2:4] \frametitle{Solution 5} \label{sec-13} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} In []: imshow(I[75:225, 75:225]) -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame}[fragile] \frametitle{Question 6} \label{sec-14} Obtain the following -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} [[12, 0], [42, 0]] [[12, 13, 14], [0, 0, 0]] -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame}[fragile] \frametitle{Solution 6} \label{sec-15} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} In []: C[::3, 1::3] In []: C[::4, 1:4] -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Summary} diff --git a/getting-started-ipython/script.rst b/getting-started-ipython/script.rst index c3e502f..5d8056c 100644 --- a/getting-started-ipython/script.rst +++ b/getting-started-ipython/script.rst @@ -16,7 +16,7 @@ .. should have ``ipython`` and ``pylab`` installed. .. Author : Puneeth - Internal Reviewer : + Internal Reviewer : Anoop Jacob Thomas External Reviewer : Checklist OK? : [2010-10-05] @@ -73,6 +73,8 @@ Let's type 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]] + Let's try out few other mathematical operations. :: @@ -95,6 +97,10 @@ 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 ``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 completes the command. This feature is called the tab-completion. @@ -105,6 +111,8 @@ 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. @@ -116,6 +124,9 @@ the commands starting with a. Now, let's see what these functions are used for. We will use the 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) :)]] + 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. @@ -136,6 +147,8 @@ 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. @@ -153,6 +166,8 @@ 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) @@ -186,6 +201,8 @@ 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. @@ -202,6 +219,9 @@ Please, pause the video here. Do the exercises and then continue. This brings us to the end of the tutorial on getting started with ``ipython``. +.. #[[Anoop: add slides for interrupts, navigating history, I feel + even a single point will also do]] + In this tutorial we have learnt, how to {{{ show the outline/summary slide. }}} @@ -218,4 +238,3 @@ This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India Hope you have enjoyed and found it useful. Thank you! - diff --git a/getting-started-ipython/slides.tex b/getting-started-ipython/slides.tex index 6850029..20af21e 100644 --- a/getting-started-ipython/slides.tex +++ b/getting-started-ipython/slides.tex @@ -1,4 +1,4 @@ -% Created 2010-10-10 Sun 17:34 +% Created 2010-10-26 Tue 10:33 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -8,6 +8,7 @@ \usepackage{float} \usepackage{wrapfig} \usepackage{soul} +\usepackage{t1enc} \usepackage{textcomp} \usepackage{marvosym} \usepackage{wasysym} diff --git a/manipulating-strings/script.rst b/manipulating-strings/script.rst index 7873575..50d5e32 100644 --- a/manipulating-strings/script.rst +++ b/manipulating-strings/script.rst @@ -17,7 +17,7 @@ .. #. basic datatypes .. Author : Puneeth - Internal Reviewer : + Internal Reviewer : Amit External Reviewer : Checklist OK? : [2010-10-05] @@ -36,6 +36,7 @@ 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. @@ -59,7 +60,7 @@ valid name of a day of the week or not. ``s`` could be in any of the forms --- sat, saturday, Sat, Saturday, -SAT, SATURDAY. We shall now be solving the problem only for the forms, +SAT, SATURDAY. For now, shall now be solving the problem only for the forms, sat and saturday. We shall solve it for the other forms, at the end of the tutorial. @@ -69,6 +70,7 @@ 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, :: @@ -82,7 +84,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. @@ -127,7 +129,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 :: @@ -157,6 +159,9 @@ Let's try it out. 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 @@ -171,6 +176,8 @@ 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.] We just convert any input string to lower case and then check if it is present in the list ``week``. -- cgit From 6b8e910cc88032d3a7d61aa49e4b969a744ffc19 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Wed, 27 Oct 2010 12:54:41 +0530 Subject: Merged Heads. --- .../getting_started_with_lists.rst | 137 ---------- getting-started-with-symbolics/quickref.tex | 8 + getting-started-with-symbolics/script.rst | 277 +++++++++++++++++++++ getting-started-with-symbolics/slides.tex | 67 +++++ symbolics/quickref.tex | 8 - symbolics/script.rst | 277 --------------------- symbolics/slides.tex | 67 ----- 7 files changed, 352 insertions(+), 489 deletions(-) delete mode 100644 getting-started-with-lists/getting_started_with_lists.rst create mode 100644 getting-started-with-symbolics/quickref.tex create mode 100644 getting-started-with-symbolics/script.rst create mode 100644 getting-started-with-symbolics/slides.tex delete mode 100644 symbolics/quickref.tex delete mode 100644 symbolics/script.rst delete mode 100644 symbolics/slides.tex diff --git a/getting-started-with-lists/getting_started_with_lists.rst b/getting-started-with-lists/getting_started_with_lists.rst deleted file mode 100644 index a82de02..0000000 --- a/getting-started-with-lists/getting_started_with_lists.rst +++ /dev/null @@ -1,137 +0,0 @@ -Hello friends and welcome to the tutorial on getting started with -lists. - - {{{ Show the slide containing title }}} - - {{{ Show the slide containing the outline slide }}} - -In this tutorial we will be getting acquainted with a python data -structure called lists. We will learn :: - - * How to create lists - * Structure of lists - * Access list elements - * Append elements to lists - * Deleting elements from lists - -List is a compound data type, it can contain data of other data -types. List is also a sequence data type, all the elements are in -order and there order has a meaning. - -We will first create an empty list with no elements. On your IPython -shell type :: - - empty = [] - type(empty) - - -This is an empty list without any elements. - -* Filled lists - -Lets now define a list, nonempty and fill it with some random elements. - -nonempty = ['spam', 'eggs', 100, 1.234] - -Thus the simplest way of creating a list is typing out a sequence -of comma-separated values (items) between square brackets. -All the list items need not have the same data type. - - - -As we can see lists can contain different kinds of data. In the -previous example 'spam' and 'eggs' are strings and 100 and 1.234 -integer and float. Thus we can put elements of heterogenous types in -lists. Thus list themselves can be one of the element types possible -in lists. Thus lists can also contain other lists. Example :: - - list_in_list=[[4,2,3,4],'and', 1, 2, 3, 4] - -We access list elements using the number of index. The -index begins from 0. So for list nonempty, nonempty[0] gives the -first element, nonempty[1] the second element and so on and -nonempty[3] the last element. :: - - nonempty[0] - nonempty[1] - nonempty[3] - -We can also access the elememts from the end using negative indices :: - - nonempty[-1] - nonempty[-2] - nonempty[-4] - --1 gives the last element which is the 4th element , -2 second to last and -4 gives the fourth -from last element which is first element. - -We can append elements to the end of a list using append command. :: - - nonempty.append('onemore') - nonempty - nonempty.append(6) - nonempty - -As we can see non empty appends 'onemore' and 6 at the end. - - - -Using len function we can check the number of elements in the list -nonempty. In this case it being 6 :: - - len(nonempty) - - - -Just like we can append elements to a list we can also remove them. -There are two ways of doing it. One is by using index. :: - - del(nonempty[1]) - - - -deletes the element at index 1, i.e the second element of the -list, 'eggs'. The other way is removing element by content. Lets say -one wishes to delete 100 from nonempty list the syntax of the command -should be :: - - a.remove(100) - -but what if their were two 100's. To check that lets do a small -experiment. :: - - a.append('spam') - a - a.remove('spam') - a - -If we check a now we will see that the first occurence 'spam' is removed -thus remove removes the first occurence of the element in the sequence -and leaves others untouched. - - -{{{Slide for Summary }}} - - -In this tutorial we came across a sequence data type called lists. :: - - * We learned how to create lists. - * How to access lists. - * Append elements to list. - * Delete Element from list. - * And Checking list length. - - - -{{{ Sponsored by Fossee Slide }}} - -This tutorial was created as a part of FOSSEE project. - -I hope you found this tutorial useful. - -Thank You - - - * Author : Amit Sethi - * First Reviewer : - * Second Reviewer : Nishanth diff --git a/getting-started-with-symbolics/quickref.tex b/getting-started-with-symbolics/quickref.tex new file mode 100644 index 0000000..b26d168 --- /dev/null +++ b/getting-started-with-symbolics/quickref.tex @@ -0,0 +1,8 @@ +Creating a linear array:\\ +{\ex \lstinline| x = linspace(0, 2*pi, 50)|} + +Plotting two variables:\\ +{\ex \lstinline| plot(x, sin(x))|} + +Plotting two lists of equal length x, y:\\ +{\ex \lstinline| plot(x, y)|} diff --git a/getting-started-with-symbolics/script.rst b/getting-started-with-symbolics/script.rst new file mode 100644 index 0000000..b9014bf --- /dev/null +++ b/getting-started-with-symbolics/script.rst @@ -0,0 +1,277 @@ +Symbolics with Sage +------------------- + +Hello friends and welcome to the tutorial on symbolics with sage. + +{{{ Show welcome slide }}} + + +.. #[Madhu: What is this line doing here. I don't see much use of it] + +During the course of the tutorial we will learn + +{{{ Show outline slide }}} + +* Defining symbolic expressions in sage. +* Using built-in costants and functions. +* Performing Integration, differentiation using sage. +* Defining matrices. +* Defining Symbolic functions. +* Simplifying and solving symbolic expressions and functions. + +We can use Sage for symbolic maths. + +On the sage notebook type:: + + sin(y) + +It raises a name error saying that y is not defined. But in sage we +can declare y as a symbol using var function. + + +:: + var('y') + +Now if you type:: + + sin(y) + +sage simply returns the expression. + + +Thus sage treats sin(y) as a symbolic expression . We can use +this to do symbolic maths using sage's built-in constants and +expressions.. + + +So let us try :: + + var('x,alpha,y,beta') + x^2/alpha^2+y^2/beta^2 + +taking another example + + var('theta') + sin^2(theta)+cos^2(theta) + + +Similarly, we can define many algebraic and trigonometric expressions +using sage . + + +Sage also provides a few built-in constants which are commonly used in +mathematics . + +example : pi,e,infinity , Function n gives the numerical values of all these + constants. + +{{{ Type n(pi) + n(e) + n(oo) + On the sage notebook }}} + + + +If you look into the documentation of function "n" by doing + +.. #[Madhu: "documentation of the function "n"?] + +:: + n( + +You will see what all arguments it takes and what it returns. It will be very +helpful if you look at the documentation of all functions introduced through +this script. + + + +Also we can define the no. of digits we wish to use in the numerical +value . For this we have to pass an argument digits. Type + +.. #[Madhu: "no of digits"? Also "We wish to obtain" than "we wish to + use"?] +:: + + n(pi, digits = 10) + +Apart from the constants sage also has a lot of builtin functions like +sin,cos,log,factorial,gamma,exp,arcsin etc ... +lets try some of them out on the sage notebook. + + +:: + + sin(pi/2) + + arctan(oo) + + log(e,e) + + +Given that we have defined variables like x,y etc .. , We can define +an arbitrary function with desired name in the following way.:: + + var('x') + function('f',x) + + +Here f is the name of the function and x is the independent variable . +Now we can define f(x) to be :: + + f(x) = x/2 + sin(x) + +Evaluating this function f for the value x=pi returns pi/2.:: + + f(pi) + +We can also define functions that are not continuous but defined +piecewise. Let us define a function which is a parabola between 0 +to 1 and a constant from 1 to 2 . Type the following as given on the +screen + +:: + + + var('x') + h(x)=x^2 g(x)=1 + f=Piecewise( + +{{{ Show the documentation of Piecewise }}} + +:: + f=Piecewise([[(0,1),h(x)],[(1,2),g(x)]],x) f + + + + +We can also define functions which are series + + +We first define a function f(n) in the way discussed above.:: + + var('n') + function('f', n) + + +To sum the function for a range of discrete values of n, we use the +sage function sum. + +For a convergent series , f(n)=1/n^2 we can say :: + + var('n') + function('f', n) + + f(n) = 1/n^2 + + sum(f(n), n, 1, oo) + + +Lets us now try another series :: + + + f(n) = (-1)^(n-1)*1/(2*n - 1) + sum(f(n), n, 1, oo) + + +This series converges to pi/4. + + +Moving on let us see how to perform simple calculus operations using Sage + +For example lets try an expression first :: + + diff(x**2+sin(x),x) + 2x+cos(x) + +The diff function differentiates an expression or a function. Its +first argument is expression or function and second argument is the +independent variable. + +We have already tried an expression now lets try a function :: + + f=exp(x^2)+arcsin(x) + diff(f(x),x) + +To get a higher order differential we need to add an extra third argument +for order :: + + diff( diff(f(x),x,3) + +in this case it is 3. + + +Just like differentiation of expression you can also integrate them :: + + x = var('x') + s = integral(1/(1 + (tan(x))**2),x) + s + + + +Many a times we need to find factors of an expression ,we can use the "factor" function + +:: + factor( + y = (x^100 - x^70)*(cos(x)^2 + cos(x)^2*tan(x)^2) + f = factor(y) + +One can simplify complicated expression :: + + f.simplify_full() + +This simplifies the expression fully . We can also do simplification +of just the algebraic part and the trigonometric part :: + + f.simplify_exp() + f.simplify_trig() + + + +One can also find roots of an equation by using find_root function:: + + phi = var('phi') + find_root(cos(phi)==sin(phi),0,pi/2) + +Lets substitute this solution into the equation and see we were +correct :: + + var('phi') + f(phi)=cos(phi)-sin(phi) + root=find_root(f(phi)==0,0,pi/2) + f.substitute(phi=root) + +as we can see when we substitute the value the answer is almost = 0 showing +the solution we got was correct. + + + + +Lets us now try some matrix algebra symbolically :: + + + + var('a,b,c,d') + A=matrix([[a,1,0],[0,b,0],[0,c,d]]) + A + +Now lets do some of the matrix operations on this matrix + + +:: + A.det() + A.inverse() + + + +{{{ Part of the notebook with summary }}} + +So in this tutorial we learnt how to + + +* We learnt about defining symbolic expression and functions. +* Using built-in constants and functions. +* Using to see the documentation of a function. +* Simple calculus operations . +* Substituting values in expression using substitute function. +* Creating symbolic matrices and performing operation on them . + diff --git a/getting-started-with-symbolics/slides.tex b/getting-started-with-symbolics/slides.tex new file mode 100644 index 0000000..4fc3634 --- /dev/null +++ b/getting-started-with-symbolics/slides.tex @@ -0,0 +1,67 @@ +% Created 2010-10-21 Thu 00:06 +\documentclass[presentation]{beamer} +\usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{graphicx} +\usepackage{longtable} +\usepackage{float} +\usepackage{wrapfig} +\usepackage{soul} +\usepackage{amssymb} +\usepackage{hyperref} + + +\title{Plotting Data } +\author{FOSSEE} +\date{2010-09-14 Tue} + +\begin{document} + +\maketitle + + + + + + +\begin{frame} +\frametitle{Tutorial Plan} +\label{sec-1} +\begin{itemize} + +\item Defining symbolic expressions in sage.\\ +\label{sec-1.1}% +\item Using built-in costants and functions.\\ +\label{sec-1.2}% +\item Performing Integration, differentiation using sage.\\ +\label{sec-1.3}% +\item Defining matrices.\\ +\label{sec-1.4}% +\item Defining Symbolic functions.\\ +\label{sec-1.5}% +\item Simplifying and solving symbolic expressions and functions.\\ +\label{sec-1.6}% +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-2} +\begin{itemize} + +\item We learnt about defining symbolic expression and functions.\\ +\label{sec-2.1}% +\item Using built-in constants and functions.\\ +\label{sec-2.2}% +\item Using to see the documentation of a function.\\ +\label{sec-2.3}% +\item Simple calculus operations .\\ +\label{sec-2.4}% +\item Substituting values in expression using substitute function.\\ +\label{sec-2.5}% +\item Creating symbolic matrices and performing operation on them .\\ +\label{sec-2.6}% +\end{itemize} % ends low level +\end{frame} + +\end{document} diff --git a/symbolics/quickref.tex b/symbolics/quickref.tex deleted file mode 100644 index b26d168..0000000 --- a/symbolics/quickref.tex +++ /dev/null @@ -1,8 +0,0 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} - -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} - -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} diff --git a/symbolics/script.rst b/symbolics/script.rst deleted file mode 100644 index b9014bf..0000000 --- a/symbolics/script.rst +++ /dev/null @@ -1,277 +0,0 @@ -Symbolics with Sage -------------------- - -Hello friends and welcome to the tutorial on symbolics with sage. - -{{{ Show welcome slide }}} - - -.. #[Madhu: What is this line doing here. I don't see much use of it] - -During the course of the tutorial we will learn - -{{{ Show outline slide }}} - -* Defining symbolic expressions in sage. -* Using built-in costants and functions. -* Performing Integration, differentiation using sage. -* Defining matrices. -* Defining Symbolic functions. -* Simplifying and solving symbolic expressions and functions. - -We can use Sage for symbolic maths. - -On the sage notebook type:: - - sin(y) - -It raises a name error saying that y is not defined. But in sage we -can declare y as a symbol using var function. - - -:: - var('y') - -Now if you type:: - - sin(y) - -sage simply returns the expression. - - -Thus sage treats sin(y) as a symbolic expression . We can use -this to do symbolic maths using sage's built-in constants and -expressions.. - - -So let us try :: - - var('x,alpha,y,beta') - x^2/alpha^2+y^2/beta^2 - -taking another example - - var('theta') - sin^2(theta)+cos^2(theta) - - -Similarly, we can define many algebraic and trigonometric expressions -using sage . - - -Sage also provides a few built-in constants which are commonly used in -mathematics . - -example : pi,e,infinity , Function n gives the numerical values of all these - constants. - -{{{ Type n(pi) - n(e) - n(oo) - On the sage notebook }}} - - - -If you look into the documentation of function "n" by doing - -.. #[Madhu: "documentation of the function "n"?] - -:: - n( - -You will see what all arguments it takes and what it returns. It will be very -helpful if you look at the documentation of all functions introduced through -this script. - - - -Also we can define the no. of digits we wish to use in the numerical -value . For this we have to pass an argument digits. Type - -.. #[Madhu: "no of digits"? Also "We wish to obtain" than "we wish to - use"?] -:: - - n(pi, digits = 10) - -Apart from the constants sage also has a lot of builtin functions like -sin,cos,log,factorial,gamma,exp,arcsin etc ... -lets try some of them out on the sage notebook. - - -:: - - sin(pi/2) - - arctan(oo) - - log(e,e) - - -Given that we have defined variables like x,y etc .. , We can define -an arbitrary function with desired name in the following way.:: - - var('x') - function('f',x) - - -Here f is the name of the function and x is the independent variable . -Now we can define f(x) to be :: - - f(x) = x/2 + sin(x) - -Evaluating this function f for the value x=pi returns pi/2.:: - - f(pi) - -We can also define functions that are not continuous but defined -piecewise. Let us define a function which is a parabola between 0 -to 1 and a constant from 1 to 2 . Type the following as given on the -screen - -:: - - - var('x') - h(x)=x^2 g(x)=1 - f=Piecewise( - -{{{ Show the documentation of Piecewise }}} - -:: - f=Piecewise([[(0,1),h(x)],[(1,2),g(x)]],x) f - - - - -We can also define functions which are series - - -We first define a function f(n) in the way discussed above.:: - - var('n') - function('f', n) - - -To sum the function for a range of discrete values of n, we use the -sage function sum. - -For a convergent series , f(n)=1/n^2 we can say :: - - var('n') - function('f', n) - - f(n) = 1/n^2 - - sum(f(n), n, 1, oo) - - -Lets us now try another series :: - - - f(n) = (-1)^(n-1)*1/(2*n - 1) - sum(f(n), n, 1, oo) - - -This series converges to pi/4. - - -Moving on let us see how to perform simple calculus operations using Sage - -For example lets try an expression first :: - - diff(x**2+sin(x),x) - 2x+cos(x) - -The diff function differentiates an expression or a function. Its -first argument is expression or function and second argument is the -independent variable. - -We have already tried an expression now lets try a function :: - - f=exp(x^2)+arcsin(x) - diff(f(x),x) - -To get a higher order differential we need to add an extra third argument -for order :: - - diff( diff(f(x),x,3) - -in this case it is 3. - - -Just like differentiation of expression you can also integrate them :: - - x = var('x') - s = integral(1/(1 + (tan(x))**2),x) - s - - - -Many a times we need to find factors of an expression ,we can use the "factor" function - -:: - factor( - y = (x^100 - x^70)*(cos(x)^2 + cos(x)^2*tan(x)^2) - f = factor(y) - -One can simplify complicated expression :: - - f.simplify_full() - -This simplifies the expression fully . We can also do simplification -of just the algebraic part and the trigonometric part :: - - f.simplify_exp() - f.simplify_trig() - - - -One can also find roots of an equation by using find_root function:: - - phi = var('phi') - find_root(cos(phi)==sin(phi),0,pi/2) - -Lets substitute this solution into the equation and see we were -correct :: - - var('phi') - f(phi)=cos(phi)-sin(phi) - root=find_root(f(phi)==0,0,pi/2) - f.substitute(phi=root) - -as we can see when we substitute the value the answer is almost = 0 showing -the solution we got was correct. - - - - -Lets us now try some matrix algebra symbolically :: - - - - var('a,b,c,d') - A=matrix([[a,1,0],[0,b,0],[0,c,d]]) - A - -Now lets do some of the matrix operations on this matrix - - -:: - A.det() - A.inverse() - - - -{{{ Part of the notebook with summary }}} - -So in this tutorial we learnt how to - - -* We learnt about defining symbolic expression and functions. -* Using built-in constants and functions. -* Using to see the documentation of a function. -* Simple calculus operations . -* Substituting values in expression using substitute function. -* Creating symbolic matrices and performing operation on them . - diff --git a/symbolics/slides.tex b/symbolics/slides.tex deleted file mode 100644 index 4fc3634..0000000 --- a/symbolics/slides.tex +++ /dev/null @@ -1,67 +0,0 @@ -% Created 2010-10-21 Thu 00:06 -\documentclass[presentation]{beamer} -\usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} -\usepackage[latin1]{inputenc} -\usepackage[T1]{fontenc} -\usepackage{graphicx} -\usepackage{longtable} -\usepackage{float} -\usepackage{wrapfig} -\usepackage{soul} -\usepackage{amssymb} -\usepackage{hyperref} - - -\title{Plotting Data } -\author{FOSSEE} -\date{2010-09-14 Tue} - -\begin{document} - -\maketitle - - - - - - -\begin{frame} -\frametitle{Tutorial Plan} -\label{sec-1} -\begin{itemize} - -\item Defining symbolic expressions in sage.\\ -\label{sec-1.1}% -\item Using built-in costants and functions.\\ -\label{sec-1.2}% -\item Performing Integration, differentiation using sage.\\ -\label{sec-1.3}% -\item Defining matrices.\\ -\label{sec-1.4}% -\item Defining Symbolic functions.\\ -\label{sec-1.5}% -\item Simplifying and solving symbolic expressions and functions.\\ -\label{sec-1.6}% -\end{itemize} % ends low level -\end{frame} -\begin{frame} -\frametitle{Summary} -\label{sec-2} -\begin{itemize} - -\item We learnt about defining symbolic expression and functions.\\ -\label{sec-2.1}% -\item Using built-in constants and functions.\\ -\label{sec-2.2}% -\item Using to see the documentation of a function.\\ -\label{sec-2.3}% -\item Simple calculus operations .\\ -\label{sec-2.4}% -\item Substituting values in expression using substitute function.\\ -\label{sec-2.5}% -\item Creating symbolic matrices and performing operation on them .\\ -\label{sec-2.6}% -\end{itemize} % ends low level -\end{frame} - -\end{document} -- cgit