# HG changeset patch # User Puneeth Chaganti # Date 1286358369 -19800 # Node ID b595f90016c576ccefc926146f646743628e089b # Parent 7206fe0c03c5075daa9695696aac82fbc95593e2 Changed structure of my scripts. diff -r 7206fe0c03c5 -r b595f90016c5 accessing-pieces-arrays.rst --- a/accessing-pieces-arrays.rst Wed Oct 06 15:08:52 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,339 +0,0 @@ -======== - Script -======== - - -{{{ Screen shows welcome slide }}} - -Welcome to the tutorial on accessing pieces of arrays - -{{{ Show the outline for this tutorial }}} - -In this tutorial we shall learn to access individual elements of -arrays, get rows and columns and other chunks of arrays using -slicing and striding. - -{{{ switch back to the terminal }}} - -As usual, we start IPython, using -:: - - ipython -pylab - -Let us have two arrays, A and C, as the sample arrays that we will -use to work through this tutorial. - -:: - - A = array([12, 23, 34, 45, 56]) - - C = array([[11, 12, 13, 14, 15], - [21, 22, 23, 24, 25], - [31, 32, 33, 34, 35], - [41, 42, 43, 44, 45], - [51, 52, 53, 54, 55]]) - -Pause the video here and make sure you have the arrays A and C, -typed in correctly. - -Let us begin with the most elementary thing, accessing individual -elements. Also, let us first do it with the one-dimensional array -A, and then do the same thing with the two-dimensional array. - -To access, the element 34 in A, we say, - -:: - - A[1] - -Like lists, indexing starts from 0 in arrays, too. So, 34, the -third element has the index 2. - -Now, let us access the element 34 from C. To do this, we say -:: - - C[2, 3] - -34 is in the third row and the fourth column, and since indexing -begins from zero, the row index is 2 and column index is 3. - -Now, that we have accessed one element of the array, let us change -it. We shall change the 34 to -34 in both A and C. To do this, we -simply assign the new value after accessing the element. -:: - - A[2] = -34 - C[2, 3] = -34 - -Now that we have accessed and changed a single element, let us -access and change more than one element at a time; first rows and -then columns. - -Let us access one row of C, say the third row. We do it by saying, -:: - - C[2] - -How do we access the last row of C? We could say, -:: - - C[4] - -for the fifth row, or as with lists, use negative indexing and say -:: - - C[-1] - -Now, we could change the last row into all zeros, using either -:: - - C[-1] = [0, 0, 0, 0, 0] - -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 - -:: - - C[:, 2] - -%%1%% Pause the video here and change the last column of C to -zeroes and then resume the video. - -:: - - C[:, -1] = 0 - -Since A is one dimensional, rows and columns of A don't make much -sense. It has just one row and -:: - - A[:] - -gives the whole of A. - -%%2%% Pause the video here and change ``A`` to ``[11, 12, 13, 14, 15]`` -and then resume the video. - -To change A, we say -:: - - A[:] = [11, 12, 13, 14, 15] - -Now, that we know how to access, rows and columns of an array, we -shall learn how to access other pieces of an array. For this -purpose, we will be using image arrays. - -To read an image into an array, we use the ``imread`` command. We -shall use the image ``squares.png`` present in ``/home/fossee``. We -shall first navigate to that path in the OS and see what the image -contains. - -{{{ switch to the browser and show the image }}} - -{{{ switch back to the ipython terminal }}} - -Let us now read the data in ``squares.png`` into the array ``I``. -:: - - I = imread('/home/fossee/squares.png') - -We can see the contents of the image, using the command -``imshow``. We say, -:: - - imshow(I) - -to see what has been read into ``I``. - -To see that ``I`` is really, just an array, we say, -:: - - I - -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 -:: - - I.shape - -to get the dimensions of the image. As we can see, ``squares.png`` -has the dimensions of 300x300. - -Our goal for this part of the tutorial would be to get the -top-left quadrant of the image. To do this, we need to access, a -few of the rows and a few of the columns of the array. - -To access, the third column of C, we said, ``C[:, 2]``. Essentially, -we are accessing all the rows in column three of C. Now, let us -modify this to access only the first three rows, of column three -of C. - -We say, -:: - - C[0:3, 2] - -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 -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. - -Now, if we wish to access the elements of row with index 2, and in -columns indexed 0 to 2 (included), we say, -:: - - C[2, 0:3] - -E%% %% Pause the video here, and 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]. Then, resume the -video. -:: - - C[1, 1:3] - -gives the elements [22, 23] -:: - - C[0:4, 0] - -gives the elements [11, 21, 31, 41] -:: - - C[1:5, 0] - -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, -:: - - C[:4, 0] - -and -:: - - C[1:, 0] - -gives the elements [21, 31, 41, 0]. If we skip both the indexes, -we get the slice from end to end, as we already know. - -E%% %% Pause the video here. Obtain the elements [[23, 24], [33, --34]] and then resume the video. -:: - - C[1:3, 2:4] - -gives us the elements, [[23, 24], [33, -34]]. - -Now, we wish to obtain the top left quarter of the image. How do -we go about doing it? Since, we know the shape of the image to be -300, we know that we need to get the first 150 rows and first 150 -columns. -:: - - I[:150, :150] - -gives us the top-left corner of the image. - -We use the ``imshow`` command to see the slice we obtained in the -form of an image and confirm. -:: - - imshow(I[:150, :150]) - -E%% %% Pause the video here, and obtain the square in the center -of the image. -:: - - imshow(I[75:225, 75:225]) - -Our next goal is to compress the image, using a very simple -technique to reduce the space that the image takes on disk while -not compromising too heavily on the image quality. The idea is to -drop alternate rows and columns of the image and save it. This way -we will be reducing the data to a fourth of the original data but -losing only so much of visual information. - -We shall first learn the idea of striding using the smaller array -C. Suppose we wish to access only the odd rows and columns (first, -third, fifth). We do this by, -:: - - C[0:5:2, 0:5:2] - -if we wish to be explicit, or simply, -:: - - C[::2, ::2] - -This is very similar to the step specified to the ``range`` -function. It specifies, the jump or step in which to move, while -accessing the elements. If no step is specified, a default value -of 1 is assumed. -:: - - C[1::2, ::2] - -gives the elements, [[21, 23, 0], [41, 43, 0]] - -E%% %% Pause the video here, and obtain the following. -[[12, 0], [42, 0]] -[[12, 13, 14], [0, 0, 0]] -Then, resume the video. -:: - - C[::3, 1::3] - -gives the elements [[12, 0], [42, 0]] -:: - - C[::4, 1:4] - -gives the elements [[12, 13, 14], [0, 0, 0]] - -Now, that we know how to stride over an image, we can drop -alternate rows and columns out of the image in I. -:: - - I[::2, ::2] - -To see this image, we say, -:: - - imshow(I[::2, ::2]) - -This does not have much data to notice any real difference, but -notice that the scale has reduced to show that we have dropped -alternate rows and columns. If you notice carefully, you will be -able to observe some blurring near the edges. To notice this -effect more clearly, increase the step to 4. -:: - - imshow(I[::4, ::4]) - -{{{ show summary slide }}} - -That brings us to the end of this tutorial. In this tutorial, we -have learnt to access parts of arrays, specifically individual -elements, rows and columns and larger pieces of arrays. We have -also learnt how to modify arrays, element wise or in larger -pieces. - -Thank You! diff -r 7206fe0c03c5 -r b595f90016c5 accessing-pieces-arrays/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/accessing-pieces-arrays/questions.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,17 @@ +Objective +--------- + +.. A mininum of 8 questions here. + +1. Question 1 +2. Question 2 +3. Question 3 + + +Larger Questions +---------------- + +.. A minimum of 2 questions here. + +1. Programming Assignment 1 +2. Programming Assignment 2 diff -r 7206fe0c03c5 -r b595f90016c5 accessing-pieces-arrays/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/accessing-pieces-arrays/quickref.tex Wed Oct 06 15:16:09 2010 +0530 @@ -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 -r 7206fe0c03c5 -r b595f90016c5 accessing-pieces-arrays/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/accessing-pieces-arrays/script.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,380 @@ +.. Objectives +.. ---------- + +.. Clearly state the objectives of the LO (along with RBT level) + +.. Prerequisites +.. ------------- + +.. 1. Name of LO-1 +.. 2. Name of LO-2 +.. 3. Name of LO-3 + +.. Author : Puneeth + Internal Reviewer : + External Reviewer : + Checklist OK? : [2010-10-05] + +Script +------ + + +{{{ Screen shows welcome slide }}} + +Welcome to the tutorial on accessing pieces of arrays + +{{{ Show the outline for this tutorial }}} + +In this tutorial we shall learn to access individual elements of +arrays, get rows and columns and other chunks of arrays using +slicing and striding. + +{{{ switch back to the terminal }}} + +As usual, we start IPython, using +:: + + ipython -pylab + +Let us have two arrays, A and C, as the sample arrays that we will +use to work through this tutorial. + +:: + + A = array([12, 23, 34, 45, 56]) + + C = array([[11, 12, 13, 14, 15], + [21, 22, 23, 24, 25], + [31, 32, 33, 34, 35], + [41, 42, 43, 44, 45], + [51, 52, 53, 54, 55]]) + +Pause the video here and make sure you have the arrays A and C, +typed in correctly. + +Let us begin with the most elementary thing, accessing individual +elements. Also, let us first do it with the one-dimensional array +A, and then do the same thing with the two-dimensional array. + +To access, the element 34 in A, we say, + +:: + + A[1] + +Like lists, indexing starts from 0 in arrays, too. So, 34, the +third element has the index 2. + +Now, let us access the element 34 from C. To do this, we say +:: + + C[2, 3] + +34 is in the third row and the fourth column, and since indexing +begins from zero, the row index is 2 and column index is 3. + +Now, that we have accessed one element of the array, let us change +it. We shall change the 34 to -34 in both A and C. To do this, we +simply assign the new value after accessing the element. +:: + + A[2] = -34 + C[2, 3] = -34 + +Now that we have accessed and changed a single element, let us +access and change more than one element at a time; first rows and +then columns. + +Let us access one row of C, say the third row. We do it by saying, +:: + + C[2] + +How do we access the last row of C? We could say, +:: + + C[4] + +for the fifth row, or as with lists, use negative indexing and say +:: + + C[-1] + +Now, we could change the last row into all zeros, using either +:: + + C[-1] = [0, 0, 0, 0, 0] + +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 + +:: + + C[:, 2] + +Following is an exercise that you must do. + +%%1%% Change the last column of C to zeroes. + +Please, pause the video here. Do the exercises and then continue. + +:: + + C[:, -1] = 0 + +Since A is one dimensional, rows and columns of A don't make much +sense. It has just one row and +:: + + A[:] + +gives the whole of A. + +Following is an exercise that you must do. + +%%2%% Change ``A`` to ``[11, 12, 13, 14, 15]``. + +Please, pause the video here. Do the exercises and then continue. + +To change A, we say +:: + + A[:] = [11, 12, 13, 14, 15] + +Now, that we know how to access, rows and columns of an array, we +shall learn how to access other pieces of an array. For this +purpose, we will be using image arrays. + +To read an image into an array, we use the ``imread`` command. We +shall use the image ``squares.png`` present in ``/home/fossee``. We +shall first navigate to that path in the OS and see what the image +contains. + +{{{ switch to the browser and show the image }}} + +{{{ switch back to the ipython terminal }}} + +Let us now read the data in ``squares.png`` into the array ``I``. +:: + + I = imread('/home/fossee/squares.png') + +We can see the contents of the image, using the command +``imshow``. We say, +:: + + imshow(I) + +to see what has been read into ``I``. We do not see white and black +because, ``pylab`` has mapped white and black to different +colors. This can be changed by using a different colormap. + +To see that ``I`` is really, just an array, we say, +:: + + I + +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 +:: + + I.shape + +to get the dimensions of the image. As we can see, ``squares.png`` +has the dimensions of 300x300. + +Our goal for this part of the tutorial would be to get the +top-left quadrant of the image. To do this, we need to access, a +few of the rows and a few of the columns of the array. + +To access, the third column of C, we said, ``C[:, 2]``. Essentially, +we are accessing all the rows in column three of C. Now, let us +modify this to access only the first three rows, of column three +of C. + +We say, +:: + + C[0:3, 2] + +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 +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. + +Now, if we wish to access the elements of row with index 2, and in +columns indexed 0 to 2 (included), we say, +:: + + C[2, 0:3] + +Following is an exercise that you must do. + +%%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. + +:: + + C[1, 1:3] + +gives the elements [22, 23] +:: + + C[0:4, 0] + +gives the elements [11, 21, 31, 41] +:: + + C[1:5, 0] + +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, +:: + + C[:4, 0] + +and +:: + + C[1:, 0] + +gives the elements [21, 31, 41, 0]. If we skip both the indexes, +we get the slice from end to end, as we already know. + +Following is an exercise that you must do. + +%%4%% Obtain the elements [[23, 24], [33, -34]] from C. + +Please, pause the video here. Do the exercises and then continue. + +:: + + C[1:3, 2:4] + +gives us the elements, [[23, 24], [33, -34]]. + +Now, we wish to obtain the top left quarter of the image. How do +we go about doing it? Since, we know the shape of the image to be +300, we know that we need to get the first 150 rows and first 150 +columns. +:: + + I[:150, :150] + +gives us the top-left corner of the image. + +We use the ``imshow`` command to see the slice we obtained in the +form of an image and confirm. +:: + + imshow(I[:150, :150]) + +Following is an exercise that you must do. + +%%5%% Pause the video here, and obtain the square in the center +of the image. + +Following is an exercise that you must do. + +:: + + imshow(I[75:225, 75:225]) + +Our next goal is to compress the image, using a very simple +technique to reduce the space that the image takes on disk while +not compromising too heavily on the image quality. The idea is to +drop alternate rows and columns of the image and save it. This way +we will be reducing the data to a fourth of the original data but +losing only so much of visual information. + +We shall first learn the idea of striding using the smaller array +C. Suppose we wish to access only the odd rows and columns (first, +third, fifth). We do this by, +:: + + C[0:5:2, 0:5:2] + +if we wish to be explicit, or simply, +:: + + C[::2, ::2] + +This is very similar to the step specified to the ``range`` +function. It specifies, the jump or step in which to move, while +accessing the elements. If no step is specified, a default value +of 1 is assumed. +:: + + C[1::2, ::2] + +gives the elements, [[21, 23, 0], [41, 43, 0]] + +Following is an exercise that you must do. + +%%6%% Obtain the following. +[[12, 0], [42, 0]] +[[12, 13, 14], [0, 0, 0]] + +Please, pause the video here. Do the exercises and then continue. + +:: + + C[::3, 1::3] + +gives the elements [[12, 0], [42, 0]] +:: + + C[::4, 1:4] + +gives the elements [[12, 13, 14], [0, 0, 0]] + +Now, that we know how to stride over an image, we can drop +alternate rows and columns out of the image in I. +:: + + I[::2, ::2] + +To see this image, we say, +:: + + imshow(I[::2, ::2]) + +This does not have much data to notice any real difference, but +notice that the scale has reduced to show that we have dropped +alternate rows and columns. If you notice carefully, you will be +able to observe some blurring near the edges. To notice this +effect more clearly, increase the step to 4. +:: + + imshow(I[::4, ::4]) + +{{{ show summary slide }}} + +That brings us to the end of this tutorial. In this tutorial, we +have learnt to access parts of arrays, specifically individual +elements, rows and columns and larger pieces of arrays. We have +also learnt how to modify arrays, element wise or in larger +pieces. + +Thank You! diff -r 7206fe0c03c5 -r b595f90016c5 accessing-pieces-arrays/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/accessing-pieces-arrays/slides.tex Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,106 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Tutorial slides on Python. +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[14pt,compress]{beamer} +%\documentclass[draft]{beamer} +%\documentclass[compress,handout]{beamer} +%\usepackage{pgfpages} +%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] + +% Modified from: generic-ornate-15min-45min.de.tex +\mode +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} +} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +%\usepackage{times} +\usepackage[T1]{fontenc} + +\usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} +\usepackage[scaled=.95]{helvet} + +\definecolor{darkgreen}{rgb}{0,0.5,0} + +\usepackage{listings} +\lstset{language=Python, + basicstyle=\ttfamily\bfseries, + commentstyle=\color{red}\itshape, + stringstyle=\color{darkgreen}, + showstringspaces=false, + keywordstyle=\color{blue}\bfseries} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Macros +\setbeamercolor{emphbar}{bg=blue!20, fg=black} +\newcommand{\emphbar}[1] +{\begin{beamercolorbox}[rounded=true]{emphbar} + {#1} + \end{beamercolorbox} +} +\newcounter{time} +\setcounter{time}{0} +\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} + +\newcommand{\typ}[1]{\lstinline{#1}} + +\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } + +% Title page +\title{Your Title Here} + +\author[FOSSEE] {FOSSEE} + +\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +\date{} + +% DOCUMENT STARTS +\begin{document} + +\begin{frame} + \maketitle +\end{frame} + +\begin{frame}[fragile] + \frametitle{Outline} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% All other slides here. %% +%% The same slides will be used in a classroom setting. %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] + \frametitle{Summary} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +\begin{frame} + \frametitle{Thank you!} + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +\end{frame} + +\end{document} diff -r 7206fe0c03c5 -r b595f90016c5 accessing-pieces-arrays/squares.png Binary file accessing-pieces-arrays/squares.png has changed diff -r 7206fe0c03c5 -r b595f90016c5 advanced-features-functions.rst --- a/advanced-features-functions.rst Wed Oct 06 15:08:52 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,203 +0,0 @@ -======== - Script -======== - -{{{ show the welcome slide }}} - -Welcome to the tutorial on advanced feature of functions. - -{{{ show the outline slide }}} - -In this tutorial we shall be looking at specifying default arguments -to functions when defining them and calling functions using keyword -arguments. We shall also, look at some of the built-in functions -available in the standard library of Python. - -{{{ switch to terminal }}} - -We have an ``ipython`` terminal open, which we shall be using through -out this session. - -Let's use the ``round`` function as an example to understand what a -default value of an argument means. Let's type the following -expressions in the terminal. - -:: - - round(2.484) - - round(2.484, 2) - -Both the first expression and the second are calls to the ``round`` -function, but the first calls it with only one argument and the second -calls it with two arguments. By observing the output, we can guess -that the first one is equivalent to call with the second argument -being 0. 0 is the default value of the argument. - -{{{ show a slide with examples of functions showing default values }}} -:: - - s.strip() # strips on spaces. - s.strip('@') # strips the string of '@' symbols. - - plot(x, y) # plots with x vs. y using default line style. - plot(x, y, 'o') # plots x vs. y with circle markers. - - linspace(0, 2*pi, 100) # returns 100 points between 0 and 2pi - linspace(0, 2*pi) # returns 50 points between 0 and 2pi - -#[punch: all above content goes on to a slide] - -{{{ switch back to ipython }}} - -Let's now define a simple function that uses default arguments. We -define a simple function that prints a welcome message to a person, -given a greeting and his/her name. - -:: - - def welcome(greet, name="World"): - print greet, name - -Let us first call the function with two arguments, one for ``greet`` -and other for ``name``. - -:: - - welcome("Hi", "Guido") - -We get the expected welcome message, "Hi Guido". - -Now let us call the function with just one argument "Hello". -:: - - welcome("Hello") - -"Hello" is treated as the ``greet`` and we get "Hello World" as -the output. "World" is the default value for the argument ``name``. - -E%% %% Pause the video here and redefine the function ``welcome``, by -interchanging it's arguments. Place the ``name`` argument with it's -default value of "Hello" before the ``greet`` argument. Then, resume -the video. - -:: - - def welcome(name="World", greet): - print greet, name - -We get an error that reads ``SyntaxError: non-default argument follows -default argument``. When defining a function all the argument with -default values should come at the end. - -E%% %% Pause the video here and type ``linspace?`` to see the -definition of the command and notice how all the arguments with -default values are towards the end. - -:: - - linspace? - -E%% %% Pause the video here and redefine the function ``welcome`` with -a default value of "Hello" to the ``greet`` argument. Then, call the -function without any arguments. Then, resume the video. - -:: - - def welcome(greet="Hello", name="World"): - print greet, name - - - welcome() - - -Let us now learn what keyword arguments are. - -{{{ show a slide with examples using keyword arguments. }}} -:: - - legend(['sin(2y)'], loc = 'center') - - plot(y, sin(y), 'g', linewidth = 2) - - annotate('local max', xy = (1.5, 1)) - - pie(science.values(), labels = science.keys()) - -When you are calling functions in Python, you don't need to remember -the order in which to pass the arguments. Instead, you can use the -name of the argument to pass it a value. This slide shows a few -function calls that use keyword arguments. ``loc``, ``linewidth``, -``xy`` and ``labels`` are being called with keyword arguments. - -{{{ switch to ipython terminal }}} - -Let us try and understand this better using the ``welcome`` function -that we have been using all along. Let us call it in different ways -and observe the output to see how keyword arguments work. - -:: - - welcome() - - welcome("Hello", "James") - - welcome("Hi", name="Guido") - -When no keyword is specified, the arguments are allotted based on -their position. So, "Hi" is the value of the argument ``greet`` and -name is passed the value "Guido". -:: - - welcome(name="Guido", greet="Hey! ") - -When keyword arguments are used, the arguments can be called in any -order. - -:: - - welcome(name="Guido", "Hey") - -This call returns an error that reads, ``non keyword arg after keyword -arg``. Python expects all the keyword to be present towards the end. - -That brings us to the end of what we wanted to learn about ``keyword`` -arguments. - -{{{ switch to a slide showing variety of functions with uses }}} - -Before defining a function of your own, make sure that you check the -standard library, for a similar function. Python is popularly called a -"Batteries included" language, for the huge library that comes along -with it. - -:: - - Math functions - abs, sin, .... - -#[punch: Need to decide, exactly what to put here. Reviewer comments - welcome.] - - -{{{ switch to slide showing classes of functions in pylab, scipy }}} - -Apart from the standard library there are other libraries like ``pylab``, -``scipy``, etc which have a huge collection of functions for scientific -purposes. -:: - - pylab - plot, bar, contour, boxplot, errorbar, log, polar, quiver, semilog - - scipy (modules) - fftpack, stats, linalg, ndimage, signal, optimize, integrate - -{{{ switch slide to summary slide }}} - -That brings us to the end of this tutorial. In this tutorial we have -learnt how to use functions with default values and keyword -arguments. We also looked at the range of functions available in the -Python standard library and the Scientific Computing related -packages. - -Thank You! diff -r 7206fe0c03c5 -r b595f90016c5 advanced-features-functions/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/advanced-features-functions/questions.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,17 @@ +Objective +--------- + +.. A mininum of 8 questions here. + +1. Question 1 +2. Question 2 +3. Question 3 + + +Programming +----------- + +.. A minimum of 2 questions here. + +1. Programming Assignment 1 +2. Programming Assignment 2 diff -r 7206fe0c03c5 -r b595f90016c5 advanced-features-functions/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/advanced-features-functions/quickref.tex Wed Oct 06 15:16:09 2010 +0530 @@ -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 -r 7206fe0c03c5 -r b595f90016c5 advanced-features-functions/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/advanced-features-functions/script.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,203 @@ +======== + Script +======== + +{{{ show the welcome slide }}} + +Welcome to the tutorial on advanced feature of functions. + +{{{ show the outline slide }}} + +In this tutorial we shall be looking at specifying default arguments +to functions when defining them and calling functions using keyword +arguments. We shall also, look at some of the built-in functions +available in the standard library of Python. + +{{{ switch to terminal }}} + +We have an ``ipython`` terminal open, which we shall be using through +out this session. + +Let's use the ``round`` function as an example to understand what a +default value of an argument means. Let's type the following +expressions in the terminal. + +:: + + round(2.484) + + round(2.484, 2) + +Both the first expression and the second are calls to the ``round`` +function, but the first calls it with only one argument and the second +calls it with two arguments. By observing the output, we can guess +that the first one is equivalent to call with the second argument +being 0. 0 is the default value of the argument. + +{{{ show a slide with examples of functions showing default values }}} +:: + + s.strip() # strips on spaces. + s.strip('@') # strips the string of '@' symbols. + + plot(x, y) # plots with x vs. y using default line style. + plot(x, y, 'o') # plots x vs. y with circle markers. + + linspace(0, 2*pi, 100) # returns 100 points between 0 and 2pi + linspace(0, 2*pi) # returns 50 points between 0 and 2pi + +#[punch: all above content goes on to a slide] + +{{{ switch back to ipython }}} + +Let's now define a simple function that uses default arguments. We +define a simple function that prints a welcome message to a person, +given a greeting and his/her name. + +:: + + def welcome(greet, name="World"): + print greet, name + +Let us first call the function with two arguments, one for ``greet`` +and other for ``name``. + +:: + + welcome("Hi", "Guido") + +We get the expected welcome message, "Hi Guido". + +Now let us call the function with just one argument "Hello". +:: + + welcome("Hello") + +"Hello" is treated as the ``greet`` and we get "Hello World" as +the output. "World" is the default value for the argument ``name``. + +E%% %% Pause the video here and redefine the function ``welcome``, by +interchanging it's arguments. Place the ``name`` argument with it's +default value of "Hello" before the ``greet`` argument. Then, resume +the video. + +:: + + def welcome(name="World", greet): + print greet, name + +We get an error that reads ``SyntaxError: non-default argument follows +default argument``. When defining a function all the argument with +default values should come at the end. + +E%% %% Pause the video here and type ``linspace?`` to see the +definition of the command and notice how all the arguments with +default values are towards the end. + +:: + + linspace? + +E%% %% Pause the video here and redefine the function ``welcome`` with +a default value of "Hello" to the ``greet`` argument. Then, call the +function without any arguments. Then, resume the video. + +:: + + def welcome(greet="Hello", name="World"): + print greet, name + + + welcome() + + +Let us now learn what keyword arguments are. + +{{{ show a slide with examples using keyword arguments. }}} +:: + + legend(['sin(2y)'], loc = 'center') + + plot(y, sin(y), 'g', linewidth = 2) + + annotate('local max', xy = (1.5, 1)) + + pie(science.values(), labels = science.keys()) + +When you are calling functions in Python, you don't need to remember +the order in which to pass the arguments. Instead, you can use the +name of the argument to pass it a value. This slide shows a few +function calls that use keyword arguments. ``loc``, ``linewidth``, +``xy`` and ``labels`` are being called with keyword arguments. + +{{{ switch to ipython terminal }}} + +Let us try and understand this better using the ``welcome`` function +that we have been using all along. Let us call it in different ways +and observe the output to see how keyword arguments work. + +:: + + welcome() + + welcome("Hello", "James") + + welcome("Hi", name="Guido") + +When no keyword is specified, the arguments are allotted based on +their position. So, "Hi" is the value of the argument ``greet`` and +name is passed the value "Guido". +:: + + welcome(name="Guido", greet="Hey! ") + +When keyword arguments are used, the arguments can be called in any +order. + +:: + + welcome(name="Guido", "Hey") + +This call returns an error that reads, ``non keyword arg after keyword +arg``. Python expects all the keyword to be present towards the end. + +That brings us to the end of what we wanted to learn about ``keyword`` +arguments. + +{{{ switch to a slide showing variety of functions with uses }}} + +Before defining a function of your own, make sure that you check the +standard library, for a similar function. Python is popularly called a +"Batteries included" language, for the huge library that comes along +with it. + +:: + + Math functions - abs, sin, .... + +#[punch: Need to decide, exactly what to put here. Reviewer comments + welcome.] + + +{{{ switch to slide showing classes of functions in pylab, scipy }}} + +Apart from the standard library there are other libraries like ``pylab``, +``scipy``, etc which have a huge collection of functions for scientific +purposes. +:: + + pylab + plot, bar, contour, boxplot, errorbar, log, polar, quiver, semilog + + scipy (modules) + fftpack, stats, linalg, ndimage, signal, optimize, integrate + +{{{ switch slide to summary slide }}} + +That brings us to the end of this tutorial. In this tutorial we have +learnt how to use functions with default values and keyword +arguments. We also looked at the range of functions available in the +Python standard library and the Scientific Computing related +packages. + +Thank You! diff -r 7206fe0c03c5 -r b595f90016c5 advanced-features-functions/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/advanced-features-functions/slides.tex Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,106 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Tutorial slides on Python. +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[14pt,compress]{beamer} +%\documentclass[draft]{beamer} +%\documentclass[compress,handout]{beamer} +%\usepackage{pgfpages} +%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] + +% Modified from: generic-ornate-15min-45min.de.tex +\mode +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} +} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +%\usepackage{times} +\usepackage[T1]{fontenc} + +\usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} +\usepackage[scaled=.95]{helvet} + +\definecolor{darkgreen}{rgb}{0,0.5,0} + +\usepackage{listings} +\lstset{language=Python, + basicstyle=\ttfamily\bfseries, + commentstyle=\color{red}\itshape, + stringstyle=\color{darkgreen}, + showstringspaces=false, + keywordstyle=\color{blue}\bfseries} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Macros +\setbeamercolor{emphbar}{bg=blue!20, fg=black} +\newcommand{\emphbar}[1] +{\begin{beamercolorbox}[rounded=true]{emphbar} + {#1} + \end{beamercolorbox} +} +\newcounter{time} +\setcounter{time}{0} +\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} + +\newcommand{\typ}[1]{\lstinline{#1}} + +\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } + +% Title page +\title{Your Title Here} + +\author[FOSSEE] {FOSSEE} + +\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +\date{} + +% DOCUMENT STARTS +\begin{document} + +\begin{frame} + \maketitle +\end{frame} + +\begin{frame}[fragile] + \frametitle{Outline} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% All other slides here. %% +%% The same slides will be used in a classroom setting. %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] + \frametitle{Summary} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +\begin{frame} + \frametitle{Thank you!} + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +\end{frame} + +\end{document} diff -r 7206fe0c03c5 -r b595f90016c5 getting-started-files.rst --- a/getting-started-files.rst Wed Oct 06 15:08:52 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -======== - Script -======== - -Welcome to the tutorial on getting started with files. - -{{{ Screen shows welcome slide }}} - -{{{ Show the outline for this tutorial }}} - -In this tutorial we shall learn to read files, and do some basic -actions on the file, like opening and reading a file, closing a -file, iterating through the file line-by-line, and appending the -lines of a file to a list. - -{{{ switch back to the terminal }}} - -As usual, we start IPython, using -:: - - ipython -pylab - -Let us first open the file, ``pendulum.txt`` present in -``/home/fossee/``. -:: - - f = open('/home/fossee/pendulum.txt') - -``f`` is called a file object. Let us type ``f`` on the terminal to -see what it is. -:: - - f - -The file object shows, the file which is open and the mode (read -or write) in which it is open. - -We shall first learn to read the whole file into a single -variable. Later, we shall look at reading it line-by-line. We use -the ``read`` method of ``f`` to read, all the contents of the file -into the variable ``pend``. -:: - - pend = f.read() - -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`` -to see more explicitly, what it contains. -:: - - pend - -%%1%% Pause the video here and split the variable into a list, -``pend_list``, of the lines in the file and then resume the -video. Hint, use the tab command to see what methods the string -variable has. - -#[punch: should this even be put? add dependency to strings LO, -where we mention that strings have methods for manipulation. hint: -use splitlines()] -:: - - pend_list = pend.splitlines() - - pend_list - -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?] - -Let us close the file opened into f. -:: - - f.close() - -Let us again type ``f`` on the prompt to see what it shows. -:: - - f - -Notice, that it now says the file has been closed. It is a good -programming practice to close any file objects that we have -opened, after their job is done. - -Let us, now move on to reading files line-by-line. - -%%1%% Pause the video here and re-open the file ``pendulum.txt`` -with ``f`` as the file object, and then resume the video. - -We just use the up arrow until we reach the open command and issue -it again. -:: - - f = open('/home/fossee/pendulum.txt') - -Now, to read the file line-by-line, we iterate over the file -object line-by-line, using the ``for`` command. Let us iterate over -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. - -Instead of just printing the lines, let us append them to a list, -``line_list``. We first initialize an empty list, ``line_list``. -:: - - line_list = [ ] - -Let us then read the file line-by-line and then append each of the -lines, to the list. We could, as usual close the file using -``f.close`` and re-open it. But, this time, let's leave alone the -file object ``f`` and directly open the file within the for -statement. This will save us the trouble of closing the file, each -time we open it. - -for line in open('/home/fossee/pendulum.txt'): -line_list.append(line) - -Let us see what ``line_list`` contains. -:: - - line_list - -Notice that ``line_list`` is a list of the lines in the file, along -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. - -{{{ show the summary slide }}} - -That brings us to the end of this tutorial. In this tutorial we -have learnt to open and close files, read the data in the files as -a whole, using the read command or reading it line by line by -iterating over the file object. - -Thank you! - diff -r 7206fe0c03c5 -r b595f90016c5 getting-started-files/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-files/questions.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,17 @@ +Objective +--------- + +.. A mininum of 8 questions here. + +1. Question 1 +2. Question 2 +3. Question 3 + + +Programming +----------- + +.. A minimum of 2 questions here. + +1. Programming Assignment 1 +2. Programming Assignment 2 diff -r 7206fe0c03c5 -r b595f90016c5 getting-started-files/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-files/quickref.tex Wed Oct 06 15:16:09 2010 +0530 @@ -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 -r 7206fe0c03c5 -r b595f90016c5 getting-started-files/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-files/script.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,147 @@ +======== + Script +======== + +Welcome to the tutorial on getting started with files. + +{{{ Screen shows welcome slide }}} + +{{{ Show the outline for this tutorial }}} + +In this tutorial we shall learn to read files, and do some basic +actions on the file, like opening and reading a file, closing a +file, iterating through the file line-by-line, and appending the +lines of a file to a list. + +{{{ switch back to the terminal }}} + +As usual, we start IPython, using +:: + + ipython -pylab + +Let us first open the file, ``pendulum.txt`` present in +``/home/fossee/``. +:: + + f = open('/home/fossee/pendulum.txt') + +``f`` is called a file object. Let us type ``f`` on the terminal to +see what it is. +:: + + f + +The file object shows, the file which is open and the mode (read +or write) in which it is open. + +We shall first learn to read the whole file into a single +variable. Later, we shall look at reading it line-by-line. We use +the ``read`` method of ``f`` to read, all the contents of the file +into the variable ``pend``. +:: + + pend = f.read() + +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`` +to see more explicitly, what it contains. +:: + + pend + +%%1%% Pause the video here and split the variable into a list, +``pend_list``, of the lines in the file and then resume the +video. Hint, use the tab command to see what methods the string +variable has. + +#[punch: should this even be put? add dependency to strings LO, +where we mention that strings have methods for manipulation. hint: +use splitlines()] +:: + + pend_list = pend.splitlines() + + pend_list + +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?] + +Let us close the file opened into f. +:: + + f.close() + +Let us again type ``f`` on the prompt to see what it shows. +:: + + f + +Notice, that it now says the file has been closed. It is a good +programming practice to close any file objects that we have +opened, after their job is done. + +Let us, now move on to reading files line-by-line. + +%%1%% Pause the video here and re-open the file ``pendulum.txt`` +with ``f`` as the file object, and then resume the video. + +We just use the up arrow until we reach the open command and issue +it again. +:: + + f = open('/home/fossee/pendulum.txt') + +Now, to read the file line-by-line, we iterate over the file +object line-by-line, using the ``for`` command. Let us iterate over +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. + +Instead of just printing the lines, let us append them to a list, +``line_list``. We first initialize an empty list, ``line_list``. +:: + + line_list = [ ] + +Let us then read the file line-by-line and then append each of the +lines, to the list. We could, as usual close the file using +``f.close`` and re-open it. But, this time, let's leave alone the +file object ``f`` and directly open the file within the for +statement. This will save us the trouble of closing the file, each +time we open it. + +for line in open('/home/fossee/pendulum.txt'): +line_list.append(line) + +Let us see what ``line_list`` contains. +:: + + line_list + +Notice that ``line_list`` is a list of the lines in the file, along +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. + +{{{ show the summary slide }}} + +That brings us to the end of this tutorial. In this tutorial we +have learnt to open and close files, read the data in the files as +a whole, using the read command or reading it line by line by +iterating over the file object. + +Thank you! + diff -r 7206fe0c03c5 -r b595f90016c5 getting-started-files/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-files/slides.tex Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,106 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Tutorial slides on Python. +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[14pt,compress]{beamer} +%\documentclass[draft]{beamer} +%\documentclass[compress,handout]{beamer} +%\usepackage{pgfpages} +%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] + +% Modified from: generic-ornate-15min-45min.de.tex +\mode +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} +} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +%\usepackage{times} +\usepackage[T1]{fontenc} + +\usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} +\usepackage[scaled=.95]{helvet} + +\definecolor{darkgreen}{rgb}{0,0.5,0} + +\usepackage{listings} +\lstset{language=Python, + basicstyle=\ttfamily\bfseries, + commentstyle=\color{red}\itshape, + stringstyle=\color{darkgreen}, + showstringspaces=false, + keywordstyle=\color{blue}\bfseries} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Macros +\setbeamercolor{emphbar}{bg=blue!20, fg=black} +\newcommand{\emphbar}[1] +{\begin{beamercolorbox}[rounded=true]{emphbar} + {#1} + \end{beamercolorbox} +} +\newcounter{time} +\setcounter{time}{0} +\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} + +\newcommand{\typ}[1]{\lstinline{#1}} + +\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } + +% Title page +\title{Your Title Here} + +\author[FOSSEE] {FOSSEE} + +\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +\date{} + +% DOCUMENT STARTS +\begin{document} + +\begin{frame} + \maketitle +\end{frame} + +\begin{frame}[fragile] + \frametitle{Outline} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% All other slides here. %% +%% The same slides will be used in a classroom setting. %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] + \frametitle{Summary} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +\begin{frame} + \frametitle{Thank you!} + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +\end{frame} + +\end{document} diff -r 7206fe0c03c5 -r b595f90016c5 getting-started-ipython.rst --- a/getting-started-ipython.rst Wed Oct 06 15:08:52 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -======== - Script -======== - -Welcome to so and so.. - - -This tutorial will cover the basic usage of the ``ipython`` -interpreter. The following topics would be covered. - -{{{ Show slide with outline of the session. }}} - -IPython is an enhanced Python interpreter that provides features like -tabcompletion, easier access to help and many other functionalities -which are not available in the vannila Python interpreter. - -First let us see how to invoke the ``ipython`` interpreter. - -We type -:: - - ipython - -at the terminal prompt to invoke the ipython interpreter. - -We get a prompt with ``In [1]:`` after getting some information about -the version of Python installed and some help commands. - -If you get an error saying something like ``ipython is not -installed``, refer to the tutorial on how to install the packages -required for this course. - -Now, to quit the ipython interpreter, type Ctrl-D. You are prompted -asking if you really want to exit, type y to say yes and quit ipython. - -Start ipython again, as you did before. - -The prompt that you have says ``In [1]``. ``In`` stands for input and the -ipython interpreter is ready to accept input from you. - -Now let us see, how we can type some commands into the interpreter. - -Start with the simplest thing, addition. - -Let's type -:: - 1+2 - -at the prompt. IPython promptly gives back the output as 3. Notice -that the output is displayed with an ``Out[1]`` indication. - -Let's try out few other mathematical operations. -:: - - 5 - 3 - 7 - 4 - 6 * 5 - -Now let's ``print 1+2``. Instead of typing the whole thing, we make -use of the fact that IPython remembers the history of the commands -that you have already used. We use the up arrow key to go back the -command ``1+2``. We then use the left-arrow key to navigate to the -beginning of the line and add the word ``print`` and a space. Then hit -enter and observe that the interpreter prints out the value as 3, -without the Out[] indication. - -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 -``print``. - -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. - -Now, we remove all the characters and just type ``r`` and then hit -tab. IPython does not complete the command since there are many -possibilities. It just lists out all the possible completions. - -%% %% Pause the video here and type ``ab`` and hit tab to see what -happens. Next, jut type ``a`` and hit tab to see what happens. - -``ab`` tab completes to ``abs`` and ``a`` gives us a list of all -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. - -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. - -As the documentation says, ``abs`` accepts a number as an input and -returns it's absolute value. - -We say, -:: - - abs(-19) - - abs(19) - -We get 19, as expected, in both the cases. - -Does it work for decimals (or floats)? Let's try typing abs(-10.5) -and we do get back 10.5. - -%% %% Pause the video here, and look-up the documentation of ``round`` -and see how to use it. - -:: - - round? - -If you notice, there are extra square brackets around the ``ndigits``. -This means that ``ndigits`` is optional and 0 is the default value. -Optional parameters are shown in square brackets anywhere in Python -documentation. - -The function ``round``, rounds a number to a given precision. - -%% %% Pause the video here and check the output of -round(2.48) -round(2.48, 1) -round(2.48, 2) -and then resume the video. - -:: - round(2.484) - round(2.484, 1) - round(2.484, 2) - -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 -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. - -Let's now type round(2.484 and hit enter, without closing the -parenthesis. We get a prompt with dots. This prompt is the -continuation prompt of ``ipython``. It appears, the previous line is -incomplete in some way. We now complete the command by typing, the -closing parenthesis and hitting enter. We get the expected output of -2.5. - -In other instances, if we commit a typing error with a longer and more -complex expression and end up with the continuation prompt, we can -type Ctrl-C to interrupt the command and get back the ``ipython`` input -prompt. - -%% %% Pause the video here. -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. - -:: - - round(2.484 - ^C - - round(2.484, 2) - -This brings us to the end of the tutorial on getting started with -``ipython``. - -In this tutorial we have seen -{{{ show the outline/summary slide. }}} - -Thank you! - - - diff -r 7206fe0c03c5 -r b595f90016c5 getting-started-ipython/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-ipython/questions.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,17 @@ +Objective +--------- + +.. A mininum of 8 questions here. + +1. Question 1 +2. Question 2 +3. Question 3 + + +Programming +----------- + +.. A minimum of 2 questions here. + +1. Programming Assignment 1 +2. Programming Assignment 2 diff -r 7206fe0c03c5 -r b595f90016c5 getting-started-ipython/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-ipython/quickref.tex Wed Oct 06 15:16:09 2010 +0530 @@ -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 -r 7206fe0c03c5 -r b595f90016c5 getting-started-ipython/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-ipython/script.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,203 @@ +.. Objectives +.. ---------- + +.. Clearly state the objectives of the LO (along with RBT level) + +.. Prerequisites +.. ------------- + +.. 1. Name of LO-1 +.. 2. Name of LO-2 +.. 3. Name of LO-3 + +.. Author : Puneeth + Internal Reviewer : + External Reviewer : + Checklist OK? : [2010-10-05] + + +Script +------ + +{{{ Show the slide containing title }}} + +Hello Friends and Welcome to the tutorial on getting started with +``ipython``. + +{{{ Show slide with outline of the session. }}} + +This tutorial will cover the basic usage of the ``ipython`` +interpreter. The following topics would be covered. + +IPython is an enhanced Python interpreter that provides features like +tabcompletion, easier access to help and many other functionalities +which are not available in the vannila Python interpreter. + +First let us see how to invoke the ``ipython`` interpreter. + +We type +:: + + ipython + +at the terminal prompt to invoke the ipython interpreter. + +We get a prompt with ``In [1]:`` after getting some information about +the version of Python installed and some help commands. + +If you get an error saying something like ``ipython is not +installed``, refer to the tutorial on how to install the packages +required for this course. + +Now, to quit the ipython interpreter, type Ctrl-D. You are prompted +asking if you really want to exit, type y to say yes and quit ipython. + +Start ipython again, as you did before. + +The prompt that you have says ``In [1]``. ``In`` stands for input and the +ipython interpreter is ready to accept input from you. + +Now let us see, how we can type some commands into the interpreter. + +Start with the simplest thing, addition. + +Let's type +:: + 1+2 + +at the prompt. IPython promptly gives back the output as 3. Notice +that the output is displayed with an ``Out[1]`` indication. + +Let's try out few other mathematical operations. +:: + + 5 - 3 + 7 - 4 + 6 * 5 + +Now let's ``print 1+2``. Instead of typing the whole thing, we make +use of the fact that IPython remembers the history of the commands +that you have already used. We use the up arrow key to go back the +command ``1+2``. We then use the left-arrow key to navigate to the +beginning of the line and add the word ``print`` and a space. Then hit +enter and observe that the interpreter prints out the value as 3, +without the Out[] indication. + +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 +``print``. + +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. + +Now, we remove all the characters and just type ``r`` and then hit +tab. IPython does not complete the command since there are many +possibilities. It just lists out all the possible completions. + +%% %% Pause the video here and type ``ab`` and hit tab to see what +happens. Next, jut type ``a`` and hit tab to see what happens. + +``ab`` tab completes to ``abs`` and ``a`` gives us a list of all +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. + +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. + +As the documentation says, ``abs`` accepts a number as an input and +returns it's absolute value. + +We say, +:: + + abs(-19) + + abs(19) + +We get 19, as expected, in both the cases. + +Does it work for decimals (or floats)? Let's try typing abs(-10.5) +and we do get back 10.5. + +Following is an (are) exercise(s) that you must do. + +%%1%% Look-up the documentation of ``round`` and see how to use it. + +Please, pause the video here. Do the exercises and then continue. + +:: + + round? + +If you notice, there are extra square brackets around the ``ndigits``. +This means that ``ndigits`` is optional and 0 is the default value. +Optional parameters are shown in square brackets anywhere in Python +documentation. + +The function ``round``, rounds a number to a given precision. + +%% %% Pause the video here and check the output of +round(2.48) +round(2.48, 1) +round(2.48, 2) +and then resume the video. + +:: + round(2.484) + round(2.484, 1) + round(2.484, 2) + +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 +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. + +Let's now type round(2.484 and hit enter, without closing the +parenthesis. We get a prompt with dots. This prompt is the +continuation prompt of ``ipython``. It appears, the previous line is +incomplete in some way. We now complete the command by typing, the +closing parenthesis and hitting enter. We get the expected output of +2.5. + +In other instances, if we commit a typing error with a longer and more +complex expression and end up with the continuation prompt, we can +type Ctrl-C to interrupt the command and get back the ``ipython`` input +prompt. + +Following is an exercise that you must do. + +%%2%% 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. + +Please, pause the video here. Do the exercises and then continue. + +:: + + round(2.484 + ^C + + round(2.484, 2) + +This brings us to the end of the tutorial on getting started with +``ipython``. + +In this tutorial we have learnt +{{{ show the outline/summary slide. }}} + + +{{{ Show the "sponsored by FOSSEE" slide }}} + +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 -r 7206fe0c03c5 -r b595f90016c5 getting-started-ipython/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-ipython/slides.tex Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,106 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Tutorial slides on Python. +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[14pt,compress]{beamer} +%\documentclass[draft]{beamer} +%\documentclass[compress,handout]{beamer} +%\usepackage{pgfpages} +%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] + +% Modified from: generic-ornate-15min-45min.de.tex +\mode +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} +} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +%\usepackage{times} +\usepackage[T1]{fontenc} + +\usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} +\usepackage[scaled=.95]{helvet} + +\definecolor{darkgreen}{rgb}{0,0.5,0} + +\usepackage{listings} +\lstset{language=Python, + basicstyle=\ttfamily\bfseries, + commentstyle=\color{red}\itshape, + stringstyle=\color{darkgreen}, + showstringspaces=false, + keywordstyle=\color{blue}\bfseries} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Macros +\setbeamercolor{emphbar}{bg=blue!20, fg=black} +\newcommand{\emphbar}[1] +{\begin{beamercolorbox}[rounded=true]{emphbar} + {#1} + \end{beamercolorbox} +} +\newcounter{time} +\setcounter{time}{0} +\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} + +\newcommand{\typ}[1]{\lstinline{#1}} + +\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } + +% Title page +\title{Your Title Here} + +\author[FOSSEE] {FOSSEE} + +\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +\date{} + +% DOCUMENT STARTS +\begin{document} + +\begin{frame} + \maketitle +\end{frame} + +\begin{frame}[fragile] + \frametitle{Outline} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% All other slides here. %% +%% The same slides will be used in a classroom setting. %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] + \frametitle{Summary} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +\begin{frame} + \frametitle{Thank you!} + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +\end{frame} + +\end{document} diff -r 7206fe0c03c5 -r b595f90016c5 loading-data-from-files.rst --- a/loading-data-from-files.rst Wed Oct 06 15:08:52 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -======== - Script -======== - -Welcome to this tutorial on loading data from files. - -{{{ Screen shows welcome slide }}} - -We often require to plot points obtained from experimental -observations. In this tutorial we shall learn to read data from files -and save it into sequences that can later be used to plot. - -{{{ Show the outline for this tutorial }}} - -We shall use the ``loadtxt`` command to load data from files. We will -be looking at how to read a file with multiple columns of data and -load each column of data into a sequence. - -{{{ switch back to the terminal }}} - -As usual, let us start IPython, using -:: - - ipython -pylab - -Now, Let us begin with reading the file primes.txt, which contains -just a list of primes listed in a column, using the loadtxt command. -The file, in our case, is present in ``/home/fossee/primes.txt``. - -{{{ Navigate to the path in the OS, open the file and show it }}} - -.. #[punch: do we need a slide for showing the path?] - -.. We use the ``cat`` command to see the contents of this file. - -.. #[punch: should we show the cat command here? seems like a good place - to do it] :: - - cat /home/fossee/primes.txt - -.. #[Nishanth]: A problem for windows users. - Should we simply open the file and show them the data - so that we can be fine with GNU/Linux ;) and windows? - -Now let us read this list into the variable ``primes``. -:: - - primes = loadtxt('/home/fossee/primes.txt') - -``primes`` is now a sequence of primes, that was listed in the file, -``primes.txt``. - -We now type, ``print primes`` to see the sequence printed. - -We observe that all of the numbers end with a period. This is so, -because these numbers are actually read as ``floats``. We shall learn -about them, later. - -Now, let us use the ``loadtxt`` command to read a file that contains -two columns of data, ``pendulum.txt``. This file contains the length -of the pendulum in the first column and the corresponding time period -in the second. - -%%1%% Pause the video here, and use the ``cat`` command to view the -contents of this file and then resume the video. - -This is how we look at the contents of the file, ``pendulum.txt`` -:: - - cat /home/fossee/pendulum.txt - -.. #[Nishanth]: The first column is L values and second is T values - from a simle pelculum experiment. - Since you are using the variable names later in the - script. - Not necessary but can be included also. - -Let us, now, read the data into the variable ``pend``. Again, it is -assumed that the file is in ``/home/fossee/`` -:: - - pend = loadtxt('/home/fossee/pendulum.txt') - -Let us now print the variable ``pend`` and see what's in it. -:: - - print pend - -Notice that ``pend`` is not a simple sequence like ``primes``. It has -two sequences, containing both the columns of the data file. Let us -use an additional argument of the ``loadtxt`` command, to read it into -two separate, simple sequences. -:: - - L, T = loadtxt('/home/fossee/pendulum.txt', unpack=True) - -.. #[Nishanth]: It has a sequence of items in which each item contains - two values. first is l and second is t - -Let us now, print the variables L and T, to see what they contain. -:: - - print L - print T - -.. #[Nishanth]: Stress on ``unpack=True`` ?? - -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 -separate sequences instead of one complex sequence. - -{{{ show the slide with loadtxt --- other features }}} - -In this tutorial, we have learnt the basic use of the ``loadtxt`` -command, which is capable of doing a lot more than we have used it for -until now, for example - -%%2%% Pause the video here, and read the file -``pendulum_semicolon.txt`` which contains the same data as -``pendulum.txt``, but the columns are separated by semi-colons instead -of spaces. Use the IPython help to see how to do this. Once you have -finished, resume the video to look at the solution. - -{{{ switch back to the terminal }}} -:: - - L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';') - - print L - - print T - -This brings us to the end of this tutorial. - -{{{ show the summary slide }}} - -You should now be able to do the following, comfortably. - - + Read data from files, containing a single column of data using the - ``loadtxt`` command. - + Read multiple columns of data, separated by spaces or other - delimiters. - -Thank you! - diff -r 7206fe0c03c5 -r b595f90016c5 loading-data-from-files/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loading-data-from-files/questions.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,17 @@ +Objective +--------- + +.. A mininum of 8 questions here. + +1. Question 1 +2. Question 2 +3. Question 3 + + +Programming +----------- + +.. A minimum of 2 questions here. + +1. Programming Assignment 1 +2. Programming Assignment 2 diff -r 7206fe0c03c5 -r b595f90016c5 loading-data-from-files/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loading-data-from-files/quickref.tex Wed Oct 06 15:16:09 2010 +0530 @@ -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 -r 7206fe0c03c5 -r b595f90016c5 loading-data-from-files/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loading-data-from-files/script.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,146 @@ +======== + Script +======== + +Welcome to this tutorial on loading data from files. + +{{{ Screen shows welcome slide }}} + +We often require to plot points obtained from experimental +observations. In this tutorial we shall learn to read data from files +and save it into sequences that can later be used to plot. + +{{{ Show the outline for this tutorial }}} + +We shall use the ``loadtxt`` command to load data from files. We will +be looking at how to read a file with multiple columns of data and +load each column of data into a sequence. + +{{{ switch back to the terminal }}} + +As usual, let us start IPython, using +:: + + ipython -pylab + +Now, Let us begin with reading the file primes.txt, which contains +just a list of primes listed in a column, using the loadtxt command. +The file, in our case, is present in ``/home/fossee/primes.txt``. + +{{{ Navigate to the path in the OS, open the file and show it }}} + +.. #[punch: do we need a slide for showing the path?] + +.. We use the ``cat`` command to see the contents of this file. + +.. #[punch: should we show the cat command here? seems like a good place + to do it] :: + + cat /home/fossee/primes.txt + +.. #[Nishanth]: A problem for windows users. + Should we simply open the file and show them the data + so that we can be fine with GNU/Linux ;) and windows? + +Now let us read this list into the variable ``primes``. +:: + + primes = loadtxt('/home/fossee/primes.txt') + +``primes`` is now a sequence of primes, that was listed in the file, +``primes.txt``. + +We now type, ``print primes`` to see the sequence printed. + +We observe that all of the numbers end with a period. This is so, +because these numbers are actually read as ``floats``. We shall learn +about them, later. + +Now, let us use the ``loadtxt`` command to read a file that contains +two columns of data, ``pendulum.txt``. This file contains the length +of the pendulum in the first column and the corresponding time period +in the second. + +%%1%% Pause the video here, and use the ``cat`` command to view the +contents of this file and then resume the video. + +This is how we look at the contents of the file, ``pendulum.txt`` +:: + + cat /home/fossee/pendulum.txt + +.. #[Nishanth]: The first column is L values and second is T values + from a simle pelculum experiment. + Since you are using the variable names later in the + script. + Not necessary but can be included also. + +Let us, now, read the data into the variable ``pend``. Again, it is +assumed that the file is in ``/home/fossee/`` +:: + + pend = loadtxt('/home/fossee/pendulum.txt') + +Let us now print the variable ``pend`` and see what's in it. +:: + + print pend + +Notice that ``pend`` is not a simple sequence like ``primes``. It has +two sequences, containing both the columns of the data file. Let us +use an additional argument of the ``loadtxt`` command, to read it into +two separate, simple sequences. +:: + + L, T = loadtxt('/home/fossee/pendulum.txt', unpack=True) + +.. #[Nishanth]: It has a sequence of items in which each item contains + two values. first is l and second is t + +Let us now, print the variables L and T, to see what they contain. +:: + + print L + print T + +.. #[Nishanth]: Stress on ``unpack=True`` ?? + +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 +separate sequences instead of one complex sequence. + +{{{ show the slide with loadtxt --- other features }}} + +In this tutorial, we have learnt the basic use of the ``loadtxt`` +command, which is capable of doing a lot more than we have used it for +until now, for example + +%%2%% Pause the video here, and read the file +``pendulum_semicolon.txt`` which contains the same data as +``pendulum.txt``, but the columns are separated by semi-colons instead +of spaces. Use the IPython help to see how to do this. Once you have +finished, resume the video to look at the solution. + +{{{ switch back to the terminal }}} +:: + + L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';') + + print L + + print T + +This brings us to the end of this tutorial. + +{{{ show the summary slide }}} + +You should now be able to do the following, comfortably. + + + Read data from files, containing a single column of data using the + ``loadtxt`` command. + + Read multiple columns of data, separated by spaces or other + delimiters. + +Thank you! + diff -r 7206fe0c03c5 -r b595f90016c5 loading-data-from-files/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loading-data-from-files/slides.tex Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,106 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Tutorial slides on Python. +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[14pt,compress]{beamer} +%\documentclass[draft]{beamer} +%\documentclass[compress,handout]{beamer} +%\usepackage{pgfpages} +%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] + +% Modified from: generic-ornate-15min-45min.de.tex +\mode +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} +} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +%\usepackage{times} +\usepackage[T1]{fontenc} + +\usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} +\usepackage[scaled=.95]{helvet} + +\definecolor{darkgreen}{rgb}{0,0.5,0} + +\usepackage{listings} +\lstset{language=Python, + basicstyle=\ttfamily\bfseries, + commentstyle=\color{red}\itshape, + stringstyle=\color{darkgreen}, + showstringspaces=false, + keywordstyle=\color{blue}\bfseries} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Macros +\setbeamercolor{emphbar}{bg=blue!20, fg=black} +\newcommand{\emphbar}[1] +{\begin{beamercolorbox}[rounded=true]{emphbar} + {#1} + \end{beamercolorbox} +} +\newcounter{time} +\setcounter{time}{0} +\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} + +\newcommand{\typ}[1]{\lstinline{#1}} + +\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } + +% Title page +\title{Your Title Here} + +\author[FOSSEE] {FOSSEE} + +\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +\date{} + +% DOCUMENT STARTS +\begin{document} + +\begin{frame} + \maketitle +\end{frame} + +\begin{frame}[fragile] + \frametitle{Outline} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% All other slides here. %% +%% The same slides will be used in a classroom setting. %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] + \frametitle{Summary} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +\begin{frame} + \frametitle{Thank you!} + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +\end{frame} + +\end{document} diff -r 7206fe0c03c5 -r b595f90016c5 loops.rst --- a/loops.rst Wed Oct 06 15:08:52 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +0,0 @@ -======== - Script -======== - -{{{ show the welcome slide }}} - -Welcome this tutorial on loops in Python. - -{{{ show the outline slide }}} - -In this tutorial, we shall look at ``while`` and ``for`` loops. We -shall then look at the ``break``, ``continue`` and ``pass`` keywords -and how to use them. - -{{{ switch to the ipython terminal }}} - -We have an ``ipython`` terminal, that we shall use through out this -tutorial. - -We shall first begin with the ``while`` loop. The ``while`` loop is -used for repeated execution as long as a condition is ``True``. - -Let us print the squares of all the odd numbers less than 10, using -the ``while`` loop. - -:: - - i = 1 - - while i<10: - print i*i - i += 2 - -This loop prints the squares of the odd numbers below 10. - -The ``while`` loop, repeatedly checks if the condition is true and -executes the block of code within the loop, if it is. As with any -other block in Python, the code within the ``while`` block is indented -to the right by 4 spaces. - -E%% %% Pause the video here and write a ``while`` loop to print the -squares of all the even numbers below 10. Then, return to the video. - -:: - - i = 2 - - while i<10: - print i*i - i += 2 - -Let us now solve the same problem of printing the squares of all odd -numbers less than 10, using the ``for`` loop. As we know, the ``for`` -loop iterates over a list or any other sequential data type. So, we -use the ``range`` function to get a list of odd numbers below 10, and -then iterate over it and print the required stuff. - -:: - - for n in range(1, 10, 2): - print n*n - -E%% %% Pause the video here and write a ``for`` loop to print the -squares of all the even numbers below 10. Then, return to the video. - -:: - - for n in range(2, 10, 2): - print n*n - -Let us now look at how to use the keywords, ``pass``, ``break`` and -``continue``. - -As we already know, ``pass`` is just a syntactic filler. It is used -for the sake of completion of blocks, that do not have any code within -them. - -:: - - for n in range(2, 10, 2): - pass - -``break`` is used to break out of the innermost loop. The ``while`` -loop to print the squares of all the odd numbers below 10, can be -modified using the ``break`` statement, as follows -:: - - i = 1 - - while True: - print i*i - i += 2 - if i<10: - break - -``continue`` is used to skip execution of the rest of the loop on this -iteration and continue to the end of this iteration. - -Say, we wish to print the squares of all the odd numbers below 10, -which are not multiples of 3, we would modify the for loop as follows. -:: - - for n in range(1, 10, 2): - if n%3 == 0: - continue - print n*n - - -E%% %%Pause the video here and using the ``continue`` keyword modify -the ``for`` loop to print the squares of even numbers below 10, to -print the squares of only multiples of 4. (Do not modify the range -function call.) Then, resume the video. -:: - - for n in range(2, 10, 2): - if n%4: - continue - print n*n - -That brings us to the end of this tutorial. In this tutorial, we have -learnt about looping structures in Python and the use of the keywords -``pass``, ``break`` and ``continue``. - -Thank You! diff -r 7206fe0c03c5 -r b595f90016c5 loops/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loops/questions.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,17 @@ +Objective +--------- + +.. A mininum of 8 questions here. + +1. Question 1 +2. Question 2 +3. Question 3 + + +Programming +----------- + +.. A minimum of 2 questions here. + +1. Programming Assignment 1 +2. Programming Assignment 2 diff -r 7206fe0c03c5 -r b595f90016c5 loops/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loops/quickref.tex Wed Oct 06 15:16:09 2010 +0530 @@ -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 -r 7206fe0c03c5 -r b595f90016c5 loops/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loops/script.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,124 @@ +======== + Script +======== + +{{{ show the welcome slide }}} + +Welcome this tutorial on loops in Python. + +{{{ show the outline slide }}} + +In this tutorial, we shall look at ``while`` and ``for`` loops. We +shall then look at the ``break``, ``continue`` and ``pass`` keywords +and how to use them. + +{{{ switch to the ipython terminal }}} + +We have an ``ipython`` terminal, that we shall use through out this +tutorial. + +We shall first begin with the ``while`` loop. The ``while`` loop is +used for repeated execution as long as a condition is ``True``. + +Let us print the squares of all the odd numbers less than 10, using +the ``while`` loop. + +:: + + i = 1 + + while i<10: + print i*i + i += 2 + +This loop prints the squares of the odd numbers below 10. + +The ``while`` loop, repeatedly checks if the condition is true and +executes the block of code within the loop, if it is. As with any +other block in Python, the code within the ``while`` block is indented +to the right by 4 spaces. + +E%% %% Pause the video here and write a ``while`` loop to print the +squares of all the even numbers below 10. Then, return to the video. + +:: + + i = 2 + + while i<10: + print i*i + i += 2 + +Let us now solve the same problem of printing the squares of all odd +numbers less than 10, using the ``for`` loop. As we know, the ``for`` +loop iterates over a list or any other sequential data type. So, we +use the ``range`` function to get a list of odd numbers below 10, and +then iterate over it and print the required stuff. + +:: + + for n in range(1, 10, 2): + print n*n + +E%% %% Pause the video here and write a ``for`` loop to print the +squares of all the even numbers below 10. Then, return to the video. + +:: + + for n in range(2, 10, 2): + print n*n + +Let us now look at how to use the keywords, ``pass``, ``break`` and +``continue``. + +As we already know, ``pass`` is just a syntactic filler. It is used +for the sake of completion of blocks, that do not have any code within +them. + +:: + + for n in range(2, 10, 2): + pass + +``break`` is used to break out of the innermost loop. The ``while`` +loop to print the squares of all the odd numbers below 10, can be +modified using the ``break`` statement, as follows +:: + + i = 1 + + while True: + print i*i + i += 2 + if i<10: + break + +``continue`` is used to skip execution of the rest of the loop on this +iteration and continue to the end of this iteration. + +Say, we wish to print the squares of all the odd numbers below 10, +which are not multiples of 3, we would modify the for loop as follows. +:: + + for n in range(1, 10, 2): + if n%3 == 0: + continue + print n*n + + +E%% %%Pause the video here and using the ``continue`` keyword modify +the ``for`` loop to print the squares of even numbers below 10, to +print the squares of only multiples of 4. (Do not modify the range +function call.) Then, resume the video. +:: + + for n in range(2, 10, 2): + if n%4: + continue + print n*n + +That brings us to the end of this tutorial. In this tutorial, we have +learnt about looping structures in Python and the use of the keywords +``pass``, ``break`` and ``continue``. + +Thank You! diff -r 7206fe0c03c5 -r b595f90016c5 loops/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loops/slides.tex Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,106 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Tutorial slides on Python. +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[14pt,compress]{beamer} +%\documentclass[draft]{beamer} +%\documentclass[compress,handout]{beamer} +%\usepackage{pgfpages} +%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] + +% Modified from: generic-ornate-15min-45min.de.tex +\mode +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} +} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +%\usepackage{times} +\usepackage[T1]{fontenc} + +\usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} +\usepackage[scaled=.95]{helvet} + +\definecolor{darkgreen}{rgb}{0,0.5,0} + +\usepackage{listings} +\lstset{language=Python, + basicstyle=\ttfamily\bfseries, + commentstyle=\color{red}\itshape, + stringstyle=\color{darkgreen}, + showstringspaces=false, + keywordstyle=\color{blue}\bfseries} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Macros +\setbeamercolor{emphbar}{bg=blue!20, fg=black} +\newcommand{\emphbar}[1] +{\begin{beamercolorbox}[rounded=true]{emphbar} + {#1} + \end{beamercolorbox} +} +\newcounter{time} +\setcounter{time}{0} +\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} + +\newcommand{\typ}[1]{\lstinline{#1}} + +\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } + +% Title page +\title{Your Title Here} + +\author[FOSSEE] {FOSSEE} + +\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +\date{} + +% DOCUMENT STARTS +\begin{document} + +\begin{frame} + \maketitle +\end{frame} + +\begin{frame}[fragile] + \frametitle{Outline} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% All other slides here. %% +%% The same slides will be used in a classroom setting. %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] + \frametitle{Summary} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +\begin{frame} + \frametitle{Thank you!} + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +\end{frame} + +\end{document} diff -r 7206fe0c03c5 -r b595f90016c5 manipulating-strings.rst --- a/manipulating-strings.rst Wed Oct 06 15:08:52 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,179 +0,0 @@ -======== - Script -======== - -{{{ show the welcome slide }}} - -Welcome to this tutorial on manipulating strings. - -{{{ show the slide with outline }}} - -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 - -#[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. - -Let us consider a simple problem, and learn how to slice strings and -get sub-strings. - -Let's say the variable ``week`` has the list of the names of the days -of the week. - -:: - - week = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"] - - -Now given a string ``s``, we should be able to check if the string is a -valid name of a day of the week or not. - -:: - - s = saturday - - -``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 and saturday. We shall solve it for the other forms, at the end of -the tutorial. - -{{{ show these forms in a slide }}} - -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 -sub-strings. To get the first three characters of s, we say, - -:: - - s[0:3] - -Note that, we are slicing the string from the index 0 to index 3, 3 -not included. - -As we already know, the last element of the string can be accessed -using ``s[-1]``. - -%%1%% Pause the video here and obtain the sub-string excluding the -first and last characters from the string. - -:: - - s[1:-1] - -gives the a substring of s, without the first and the last -characters. - -:: - - s = saturday - s[:3] - -Now, we just check if that substring is present in the variable -``week``. - -:: - - s[:3] in week - -Let us now consider the problem of finding out if a given string is -palindromic or not. First of all, a palindromic string is a string -that remains same even when it has been reversed. - -Let the string given be ``malayalam``. - -:: - - s = "malayalam" - -Now, we need to compare this string with it's reverse. - -Again, we will use a technique common to all sequence data-types, -[::-1] - -So, we obtain the reverse of s, by simply saying, - -:: - - s[::-1] - -Now, to check if the string is ``s`` is palindromic, we say -:: - - s == s[::-1] - -As, expected, we get ``True``. - -Now, if the string we are given is ``Malayalam`` instead of -``malayalam``, the above comparison would return a False. So, we will -have to convert the string to all lower case or all upper case, before -comparing. Python provides methods, ``s.lower`` and ``s.upper`` to -achieve this. - -Let's try it out. -:: - - s = "Malayalam" - - s.upper() - - s - - s.lower() - - s.lower() == s.lower()[::-1] - -Note that these methods, do not change the original string, but return -a new string. - -a%% %% Pause the video here, and finish the problem of checking if -``s`` is a valid name of a day of the week and then resume the -video. Change the solution to this problem, to include forms like, -SAT, SATURDAY, Saturday and Sat. - -:: - - s.lower()[:3] in week - -We just convert any input string to lower case and then check if it is -present in the list ``week``. - -Now, let us consider another problem. We often encounter e-mail id's -which have @ and periods replaced with text, something like -info[at]fossee[dot]in. We now wish to get back proper e-mail -addresses. - -Let's say the variable email has the email address. -:: - - email = "info[at]fossee[dot]in" - -Now, we first replace the ``[at]`` with the ``@``, using the replace -method of strings. -:: - - email = email.replace("[at]", "@") - print email - -%%1%% Pause the video here and replace the ``[dot]`` with ``.`` and then -resume the video. - -:: - - email = email.replace("[dot]", ".") - print email - - -That brings us to the end of the tutorial. - -{{{ show summary slide }}} - -In this tutorial, we have learnt how to get substrings, reverse -strings and a few useful methods, namely upper, lower and replace. - -Thank You! diff -r 7206fe0c03c5 -r b595f90016c5 manipulating-strings/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manipulating-strings/questions.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,17 @@ +Objective +--------- + +.. A mininum of 8 questions here. + +1. Question 1 +2. Question 2 +3. Question 3 + + +Programming +----------- + +.. A minimum of 2 questions here. + +1. Programming Assignment 1 +2. Programming Assignment 2 diff -r 7206fe0c03c5 -r b595f90016c5 manipulating-strings/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manipulating-strings/quickref.tex Wed Oct 06 15:16:09 2010 +0530 @@ -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 -r 7206fe0c03c5 -r b595f90016c5 manipulating-strings/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manipulating-strings/script.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,179 @@ +======== + Script +======== + +{{{ show the welcome slide }}} + +Welcome to this tutorial on manipulating strings. + +{{{ show the slide with outline }}} + +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 + +#[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. + +Let us consider a simple problem, and learn how to slice strings and +get sub-strings. + +Let's say the variable ``week`` has the list of the names of the days +of the week. + +:: + + week = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"] + + +Now given a string ``s``, we should be able to check if the string is a +valid name of a day of the week or not. + +:: + + s = saturday + + +``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 and saturday. We shall solve it for the other forms, at the end of +the tutorial. + +{{{ show these forms in a slide }}} + +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 +sub-strings. To get the first three characters of s, we say, + +:: + + s[0:3] + +Note that, we are slicing the string from the index 0 to index 3, 3 +not included. + +As we already know, the last element of the string can be accessed +using ``s[-1]``. + +%%1%% Pause the video here and obtain the sub-string excluding the +first and last characters from the string. + +:: + + s[1:-1] + +gives the a substring of s, without the first and the last +characters. + +:: + + s = saturday + s[:3] + +Now, we just check if that substring is present in the variable +``week``. + +:: + + s[:3] in week + +Let us now consider the problem of finding out if a given string is +palindromic or not. First of all, a palindromic string is a string +that remains same even when it has been reversed. + +Let the string given be ``malayalam``. + +:: + + s = "malayalam" + +Now, we need to compare this string with it's reverse. + +Again, we will use a technique common to all sequence data-types, +[::-1] + +So, we obtain the reverse of s, by simply saying, + +:: + + s[::-1] + +Now, to check if the string is ``s`` is palindromic, we say +:: + + s == s[::-1] + +As, expected, we get ``True``. + +Now, if the string we are given is ``Malayalam`` instead of +``malayalam``, the above comparison would return a False. So, we will +have to convert the string to all lower case or all upper case, before +comparing. Python provides methods, ``s.lower`` and ``s.upper`` to +achieve this. + +Let's try it out. +:: + + s = "Malayalam" + + s.upper() + + s + + s.lower() + + s.lower() == s.lower()[::-1] + +Note that these methods, do not change the original string, but return +a new string. + +a%% %% Pause the video here, and finish the problem of checking if +``s`` is a valid name of a day of the week and then resume the +video. Change the solution to this problem, to include forms like, +SAT, SATURDAY, Saturday and Sat. + +:: + + s.lower()[:3] in week + +We just convert any input string to lower case and then check if it is +present in the list ``week``. + +Now, let us consider another problem. We often encounter e-mail id's +which have @ and periods replaced with text, something like +info[at]fossee[dot]in. We now wish to get back proper e-mail +addresses. + +Let's say the variable email has the email address. +:: + + email = "info[at]fossee[dot]in" + +Now, we first replace the ``[at]`` with the ``@``, using the replace +method of strings. +:: + + email = email.replace("[at]", "@") + print email + +%%1%% Pause the video here and replace the ``[dot]`` with ``.`` and then +resume the video. + +:: + + email = email.replace("[dot]", ".") + print email + + +That brings us to the end of the tutorial. + +{{{ show summary slide }}} + +In this tutorial, we have learnt how to get substrings, reverse +strings and a few useful methods, namely upper, lower and replace. + +Thank You! diff -r 7206fe0c03c5 -r b595f90016c5 manipulating-strings/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manipulating-strings/slides.tex Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,106 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Tutorial slides on Python. +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[14pt,compress]{beamer} +%\documentclass[draft]{beamer} +%\documentclass[compress,handout]{beamer} +%\usepackage{pgfpages} +%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] + +% Modified from: generic-ornate-15min-45min.de.tex +\mode +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} +} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +%\usepackage{times} +\usepackage[T1]{fontenc} + +\usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} +\usepackage[scaled=.95]{helvet} + +\definecolor{darkgreen}{rgb}{0,0.5,0} + +\usepackage{listings} +\lstset{language=Python, + basicstyle=\ttfamily\bfseries, + commentstyle=\color{red}\itshape, + stringstyle=\color{darkgreen}, + showstringspaces=false, + keywordstyle=\color{blue}\bfseries} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Macros +\setbeamercolor{emphbar}{bg=blue!20, fg=black} +\newcommand{\emphbar}[1] +{\begin{beamercolorbox}[rounded=true]{emphbar} + {#1} + \end{beamercolorbox} +} +\newcounter{time} +\setcounter{time}{0} +\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} + +\newcommand{\typ}[1]{\lstinline{#1}} + +\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } + +% Title page +\title{Your Title Here} + +\author[FOSSEE] {FOSSEE} + +\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +\date{} + +% DOCUMENT STARTS +\begin{document} + +\begin{frame} + \maketitle +\end{frame} + +\begin{frame}[fragile] + \frametitle{Outline} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% All other slides here. %% +%% The same slides will be used in a classroom setting. %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] + \frametitle{Summary} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +\begin{frame} + \frametitle{Thank you!} + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +\end{frame} + +\end{document} diff -r 7206fe0c03c5 -r b595f90016c5 using-sage.rst --- a/using-sage.rst Wed Oct 06 15:08:52 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,197 +0,0 @@ -======== - Script -======== - -{{{ show the welcome slide }}} - -Welcome to this tutorial on using Sage. - -{{{ show the slide with outline }}} - -In this tutorial we shall quickly look at a few examples of the areas -(name the areas, here) in which Sage can be used and how it can be -used. - -{{{ show the slide with Calculus outline }}} - -Let us begin with Calculus. We shall be looking at limits, -differentiation, integration, and Taylor polynomial. - -{{{ show sage notebook }}} - -We have our Sage notebook running. In case, you don't have it running, -start is using the command, ``sage --notebook``. - -To find the limit of the function x*sin(1/x), at x=0, we say -:: - - lim(x*sin(1/x), x=0) - -We get the limit to be 0, as expected. - -It is also possible to the limit at a point from one direction. For -example, let us find the limit of 1/x at x=0, when approaching from -the positive side. -:: - - lim(1/x, x=0, dir='above') - -To find the limit from the negative side, we say, -:: - - lim(1/x, x=0, dir='above') - -Let us now see how to differentiate, using Sage. We shall find the -differential of the expression ``exp(sin(x^2))/x`` w.r.t ``x``. We -shall first define the expression, and then use the ``diff`` function -to obtain the differential of the expression. -:: - - var('x') - f = exp(sin(x^2))/x - - diff(f, x) - -We can also obtain the partial differentiation of an expression w.r.t -one of the variables. Let us differentiate the expression -``exp(sin(y - x^2))/x`` w.r.t x and y. -:: - - var('x y') - f = exp(sin(y - x^2))/x - - diff(f, x) - - diff(f, y) - -Now, let us look at integration. We shall use the expression obtained -from the differentiation that we did before, ``diff(f, y)`` --- -``e^(sin(-x^2 + y))*cos(-x^2 + y)/x``. The ``integrate`` command is -used to obtain the integral of an expression or function. -:: - - integrate(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y) - -We get back the correct expression. The minus sign being inside or -outside the ``sin`` function doesn't change much. - -Now, let us find the value of the integral between the limits 0 and -pi/2. -:: - - integral(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y, 0, pi/2) - -Let us now see how to obtain the Taylor expansion of an expression -using sage. Let us obtain the Taylor expansion of ``(x + 1)^n`` up to -degree 4 about 0. -:: - - var('x n') - taylor((x+1)^n, x, 0, 4) - -This brings us to the end of the features of Sage for Calculus, that -we will be looking at. For more, look at the Calculus quick-ref from -the Sage Wiki. - -Next let us move on to Matrix Algebra. - -{{{ show the equation on the slides }}} - -Let us begin with solving the equation ``Ax = v``, where A is the -matrix ``matrix([[1,2],[3,4]])`` and v is the vector -``vector([1,2])``. - -To solve the equation, ``Ax = v`` we simply say -:: - - x = solve_right(A, v) - -To solve the equation, ``xA = v`` we simply say -:: - - x = solve_left(A, v) - -The left and right here, denote the position of ``A``, relative to x. - -#[Puneeth]: any suggestions on what more to add? - -Now, let us look at Graph Theory in Sage. - -We shall look at some ways to create graphs and some of the graph -families available in Sage. - -The simplest way to define an arbitrary graph is to use a dictionary -of lists. We create a simple graph by -:: - - G = Graph({0:[1,2,3], 2:[4]}) - -We say -:: - - G.show() - -to view the visualization of the graph. - -Similarly, we can obtain a directed graph using the ``DiGraph`` -function. -:: - - G = DiGraph({0:[1,2,3], 2:[4]}) - - -Sage also provides a lot of graph families which can be viewed by -typing ``graph.``. Let us obtain a complete graph with 5 vertices -and then show the graph. -:: - - G = graphs.CompleteGraph(5) - - G.show() - - -Sage provides other functions for Number theory and -Combinatorics. Let's have a glimpse of a few of them. - - -:: - - prime_range(100, 200) - -gives primes in the range 100 to 200. - -:: - - is_prime(1999) - -checks if 1999 is a prime number or not. - -:: - - factor(2001) - -gives the factorized form of 2001. - -:: - - C = Permutations([1, 2, 3, 4]) - C.list() - -gives the permutations of ``[1, 2, 3, 4]`` - -:: - - C = Combinations([1, 2, 3, 4]) - C.list() - -gives all the combinations of ``[1, 2, 3, 4]`` - -That brings us to the end of this session showing various features -available in Sage. - -{{{ Show summary slide }}} - -We have looked at some of the functions available for Linear Algebra, -Calculus, Graph Theory and Number theory. - -Thank You! diff -r 7206fe0c03c5 -r b595f90016c5 using-sage/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/using-sage/questions.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,17 @@ +Objective +--------- + +.. A mininum of 8 questions here. + +1. Question 1 +2. Question 2 +3. Question 3 + + +Programming +----------- + +.. A minimum of 2 questions here. + +1. Programming Assignment 1 +2. Programming Assignment 2 diff -r 7206fe0c03c5 -r b595f90016c5 using-sage/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/using-sage/quickref.tex Wed Oct 06 15:16:09 2010 +0530 @@ -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 -r 7206fe0c03c5 -r b595f90016c5 using-sage/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/using-sage/script.rst Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,197 @@ +======== + Script +======== + +{{{ show the welcome slide }}} + +Welcome to this tutorial on using Sage. + +{{{ show the slide with outline }}} + +In this tutorial we shall quickly look at a few examples of the areas +(name the areas, here) in which Sage can be used and how it can be +used. + +{{{ show the slide with Calculus outline }}} + +Let us begin with Calculus. We shall be looking at limits, +differentiation, integration, and Taylor polynomial. + +{{{ show sage notebook }}} + +We have our Sage notebook running. In case, you don't have it running, +start is using the command, ``sage --notebook``. + +To find the limit of the function x*sin(1/x), at x=0, we say +:: + + lim(x*sin(1/x), x=0) + +We get the limit to be 0, as expected. + +It is also possible to the limit at a point from one direction. For +example, let us find the limit of 1/x at x=0, when approaching from +the positive side. +:: + + lim(1/x, x=0, dir='above') + +To find the limit from the negative side, we say, +:: + + lim(1/x, x=0, dir='above') + +Let us now see how to differentiate, using Sage. We shall find the +differential of the expression ``exp(sin(x^2))/x`` w.r.t ``x``. We +shall first define the expression, and then use the ``diff`` function +to obtain the differential of the expression. +:: + + var('x') + f = exp(sin(x^2))/x + + diff(f, x) + +We can also obtain the partial differentiation of an expression w.r.t +one of the variables. Let us differentiate the expression +``exp(sin(y - x^2))/x`` w.r.t x and y. +:: + + var('x y') + f = exp(sin(y - x^2))/x + + diff(f, x) + + diff(f, y) + +Now, let us look at integration. We shall use the expression obtained +from the differentiation that we did before, ``diff(f, y)`` --- +``e^(sin(-x^2 + y))*cos(-x^2 + y)/x``. The ``integrate`` command is +used to obtain the integral of an expression or function. +:: + + integrate(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y) + +We get back the correct expression. The minus sign being inside or +outside the ``sin`` function doesn't change much. + +Now, let us find the value of the integral between the limits 0 and +pi/2. +:: + + integral(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y, 0, pi/2) + +Let us now see how to obtain the Taylor expansion of an expression +using sage. Let us obtain the Taylor expansion of ``(x + 1)^n`` up to +degree 4 about 0. +:: + + var('x n') + taylor((x+1)^n, x, 0, 4) + +This brings us to the end of the features of Sage for Calculus, that +we will be looking at. For more, look at the Calculus quick-ref from +the Sage Wiki. + +Next let us move on to Matrix Algebra. + +{{{ show the equation on the slides }}} + +Let us begin with solving the equation ``Ax = v``, where A is the +matrix ``matrix([[1,2],[3,4]])`` and v is the vector +``vector([1,2])``. + +To solve the equation, ``Ax = v`` we simply say +:: + + x = solve_right(A, v) + +To solve the equation, ``xA = v`` we simply say +:: + + x = solve_left(A, v) + +The left and right here, denote the position of ``A``, relative to x. + +#[Puneeth]: any suggestions on what more to add? + +Now, let us look at Graph Theory in Sage. + +We shall look at some ways to create graphs and some of the graph +families available in Sage. + +The simplest way to define an arbitrary graph is to use a dictionary +of lists. We create a simple graph by +:: + + G = Graph({0:[1,2,3], 2:[4]}) + +We say +:: + + G.show() + +to view the visualization of the graph. + +Similarly, we can obtain a directed graph using the ``DiGraph`` +function. +:: + + G = DiGraph({0:[1,2,3], 2:[4]}) + + +Sage also provides a lot of graph families which can be viewed by +typing ``graph.``. Let us obtain a complete graph with 5 vertices +and then show the graph. +:: + + G = graphs.CompleteGraph(5) + + G.show() + + +Sage provides other functions for Number theory and +Combinatorics. Let's have a glimpse of a few of them. + + +:: + + prime_range(100, 200) + +gives primes in the range 100 to 200. + +:: + + is_prime(1999) + +checks if 1999 is a prime number or not. + +:: + + factor(2001) + +gives the factorized form of 2001. + +:: + + C = Permutations([1, 2, 3, 4]) + C.list() + +gives the permutations of ``[1, 2, 3, 4]`` + +:: + + C = Combinations([1, 2, 3, 4]) + C.list() + +gives all the combinations of ``[1, 2, 3, 4]`` + +That brings us to the end of this session showing various features +available in Sage. + +{{{ Show summary slide }}} + +We have looked at some of the functions available for Linear Algebra, +Calculus, Graph Theory and Number theory. + +Thank You! diff -r 7206fe0c03c5 -r b595f90016c5 using-sage/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/using-sage/slides.tex Wed Oct 06 15:16:09 2010 +0530 @@ -0,0 +1,106 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Tutorial slides on Python. +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[14pt,compress]{beamer} +%\documentclass[draft]{beamer} +%\documentclass[compress,handout]{beamer} +%\usepackage{pgfpages} +%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] + +% Modified from: generic-ornate-15min-45min.de.tex +\mode +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} +} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +%\usepackage{times} +\usepackage[T1]{fontenc} + +\usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} +\usepackage[scaled=.95]{helvet} + +\definecolor{darkgreen}{rgb}{0,0.5,0} + +\usepackage{listings} +\lstset{language=Python, + basicstyle=\ttfamily\bfseries, + commentstyle=\color{red}\itshape, + stringstyle=\color{darkgreen}, + showstringspaces=false, + keywordstyle=\color{blue}\bfseries} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Macros +\setbeamercolor{emphbar}{bg=blue!20, fg=black} +\newcommand{\emphbar}[1] +{\begin{beamercolorbox}[rounded=true]{emphbar} + {#1} + \end{beamercolorbox} +} +\newcounter{time} +\setcounter{time}{0} +\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} + +\newcommand{\typ}[1]{\lstinline{#1}} + +\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } + +% Title page +\title{Your Title Here} + +\author[FOSSEE] {FOSSEE} + +\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +\date{} + +% DOCUMENT STARTS +\begin{document} + +\begin{frame} + \maketitle +\end{frame} + +\begin{frame}[fragile] + \frametitle{Outline} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% All other slides here. %% +%% The same slides will be used in a classroom setting. %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] + \frametitle{Summary} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +\begin{frame} + \frametitle{Thank you!} + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +\end{frame} + +\end{document}