# HG changeset patch # User Puneeth Chaganti # Date 1286948737 -19800 # Node ID c6d31837cb06d9889005346a24dd4b9db05426b2 # Parent 4bebfa8c9a0a2eb68cfbd2d5e96046cd89b8d51e# Parent 9d8fd5ea64b248143ad2b1d40fa03a88f3d49723 Merged heads. diff -r 9d8fd5ea64b2 -r c6d31837cb06 conditionals.rst --- a/conditionals.rst Tue Oct 12 17:15:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,176 +0,0 @@ -Hello friends. Welcome to this spoken tutorial on Getting started with -strings. - -{{{ Show the slide containing the title }}} - -{{{ Show the slide containing the outline }}} - -In this tutorial, we will learn the basic conditional constructs -available in Python. We learn the if/else, if/elif/else and ternary -conditional constructs available in Python. - -{{{ Shift to terminal and start ipython }}} - -To begin with let us start ipython, by typing:: - - ipython - -on the terminal - -Whenever we have two possible states that can occur depending on a -whether a certain condition we can use if/else construct in -Python. Say for example we have a variable "a" which stores integers -and we are required to find out whether the value of the variable "a" -is an even number or an odd number. To test out conditional statements -as an example, let us say the value of the variable "a" is 5:: - - a = 5 - -In such a case we can write the if/else block as:: - - if a % 2 == 0: - print "Even" - else: - print "Odd" - -When the value of the variable "a" is divided by 2 and the remainder -is 0 i.e. the result of the operation "a modulo 2" is 0 the condition -"a % 2 == 0" evaluates to True, so the code within the if block gets -executed. This means that the value of "a" is Even. - -If the operation "a modulo 2" is not 0 the condition "a % 2 == 0" -evaluates to False and hence the code block within else gets executed -which means that the value of "a" is Odd. - -Note in such a case only one of the two blocks get executed depending -on whether the condition is True or False. - -There is a very important sytactic element to understand here. All the -statements which are inside a certain code block are indented by 4 -spaces. The statement which starts a new code block after it, i.e. the -if statement in this example ends with a colon (:). So the next -immediate line will be inside the if block and hence indented by 4 -spaces. To come out of the code block we have to come back to the -previous indentation level as shown in the else line here. Again the -line following else will be in a new block so else line ends with a -colon and the following block of code is indented by 4. - -As we use if/else statement when we have a condition which can take -one of the two states, we may have conditions which can take more than -two states. In such a scenario Python provides if/elif/else -statements. Let us take an example. We have a variable "a" which holds -integer values. We need to print "positive" if the value of a is -positive, "negative" if it is negative and "zero" if the value of the -variable "a" is 0. Let us use if/elif/else ladder for it. For the -purposes of testing our code let us assume that the value of a is -3:: - - a = -3 - - if a > 0: - print "positive" - elif a < 0: - print "negative" - else: - print "zero" - -This if/elif/else ladder is self explanatory. All the syntax and rules -as said for if/else statements hold. The only addition here is the -elif statement which can have another condition of its own. - -Here, exactly one block of code is executed and that block of code -corresponds to the condition which first evaluates to True. Even if -there is a situation where multiple conditions evaluate to True all -the subsequent conditions other than the first one which evaluates to -True are neglected. Consequently, the else block gets executed if and -only if all the conditions evaluate to False. - -Also, the else block in both if/else statement and if/elif/else is -optional. We can have a single if statement or just if/elif statements -without having else block at all. Also, there can be any number of -elif's within an if/elif/else ladder. For example - -{{{ Show slide for this }}} - - if user == 'admin': - # Do admin operations - elif user == 'moderator': - # Do moderator operations - elif user == 'client': - # Do customer operations - -{{{ end of slide switch to ipython }}} - -is completely valid. Note that there are multiple elif blocks and there -is no else block. - -In addition to these conditional statements, Python provides a very -convenient ternary conditional operator. Let us take the following -example where we read the marks data from a data file which is -obtained as a string as we read a file. The marks can be in the range -of 0 to 100 or 'AA' if the student is absent. In such a case to obtain -the marks as an integer we can use the ternary conditional -operator. Let us say the string score is stored in score_str -variable:: - - score_str = 'AA' - -Now let us use the ternary conditional operator:: - - score = int(score_str) if score_str != 'AA' else 0 - -This is just the if/else statement block which written in a more -convenient form and is very helpful when we have only one statement -for each block. This conditional statement effectively means as we -would have exactly specified in the English language which will be -like score is integer of score_str is score_str is not 'AA' otherwise -it is 0. This means that we make the scores of the students who were -absent for the exam 0. - -Moving on, there are certain situations where we will have to no -operations or statements within the block of code. For example, we -have a code where we are waiting for the keyboard input. If the user -enters "s" as the input we would perform some operation nothing -otherwise. In such cases "pass" statement comes very handy:: - - a = raw_input("Enter 'c' to calculate and exit, 'd' to display the existing - results exit and 'x' to exit and any other key to continue: ") - - if a == 'c': - # Calculate the marks and exit - elif a == 'd': - # Display the results and exit - elif a == 'x': - # Exit the program - else: - pass - -In this case "pass" statement acts as a place holder for the block of -code. It is equivalent to a null operation. It literally does -nothing. So "pass" statement can be used as a null operation -statement, or it can used as a place holder when the actual code -implementation for a particular block of code is not known yet but has -to be filled up later. - -{{{ Show summary slide }}} - -This brings us to the end of the tutorial session on conditional -statements in Python. In this tutorial session we learnt - - * What are conditional statements - * if/else statement - * if/elif/else statement - * Ternary conditional statement - C if X else Y - * and the "pass" statement - -{{{ 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. -Thankyou - -.. Author : Madhu - Internal Reviewer 1 : [potential reviewer: Puneeth] - Internal Reviewer 2 : [potential reviewer: Anoop] - External Reviewer : - diff -r 9d8fd5ea64b2 -r c6d31837cb06 conditionals/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conditionals/questions.rst Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,79 @@ +Objective Questions +------------------- + +.. A mininum of 8 questions here (along with answers) + +1. Given a variable ``time``, print ``Good Morning`` if it is less + than 12, otherwise ``Hello``. + + Answer:: + + if time < 12: + print "Good Morning" + + else: + print "Hello" + +#. Every ``if`` block must be followed by an ``else`` block. T or F? + + Answer: F + +#. Every ``if/elif/else`` ladder MUST end with an ``else`` block. T/F? + + Answer: F + +#. An if/elif/else ladder can have any number of elif blocks. T or F? + + Answer: T + +#. What will be printed at the end this code block:: + + x = 20 + + if x > 10: + print x * 100 + + Answer: IndentationError - Expected and indented block.. + +#. What will be printed at the end this code block:: + + x = 20 + + if x > 10: + print x * 100 + else: + print x + + Answer: SyntaxError + +#. What will be printed at the end this code block:: + + x = 20 + + if x > 10: + print x * 100 + else: + print x + + Answer: 2000 + +#. Convert the if else ladder below into a ternary conditional + statement:: + + x = 20 + + if x > 10: + print x * 100 + else: + print x + + Answer: print x * 100 if x > 10 else x + + +Larger Questions +---------------- + +.. A minimum of 2 questions here (along with answers) + +1. Question 1 +2. Question 2 diff -r 9d8fd5ea64b2 -r c6d31837cb06 conditionals/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conditionals/quickref.tex Wed Oct 13 11:15:37 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 9d8fd5ea64b2 -r c6d31837cb06 conditionals/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conditionals/script.rst Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,192 @@ +.. 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 : Madhu + Internal Reviewer : + External Reviewer : + Checklist OK? : [2010-10-05] + + +Script +------ + +{{{ Show the slide containing the title }}} + +Hello friends. Welcome to this spoken tutorial on Getting started with +strings. + +{{{ Show the slide containing the outline }}} + +In this tutorial, we will learn the basic conditional constructs +available in Python. We learn the if/else, if/elif/else and ternary +conditional constructs available in Python. + +{{{ Shift to terminal and start ipython }}} + +To begin with let us start ipython, by typing:: + + ipython + +on the terminal + +Whenever we have two possible states that can occur depending on a +whether a certain condition we can use if/else construct in +Python. Say for example we have a variable "a" which stores integers +and we are required to find out whether the value of the variable "a" +is an even number or an odd number. To test out conditional statements +as an example, let us say the value of the variable "a" is 5:: + + a = 5 + +In such a case we can write the if/else block as:: + + if a % 2 == 0: + print "Even" + else: + print "Odd" + +When the value of the variable "a" is divided by 2 and the remainder +is 0 i.e. the result of the operation "a modulo 2" is 0 the condition +"a % 2 == 0" evaluates to True, so the code within the if block gets +executed. This means that the value of "a" is Even. + +If the operation "a modulo 2" is not 0 the condition "a % 2 == 0" +evaluates to False and hence the code block within else gets executed +which means that the value of "a" is Odd. + +Note in such a case only one of the two blocks get executed depending +on whether the condition is True or False. + +There is a very important sytactic element to understand here. All the +statements which are inside a certain code block are indented by 4 +spaces. The statement which starts a new code block after it, i.e. the +if statement in this example ends with a colon (:). So the next +immediate line will be inside the if block and hence indented by 4 +spaces. To come out of the code block we have to come back to the +previous indentation level as shown in the else line here. Again the +line following else will be in a new block so else line ends with a +colon and the following block of code is indented by 4. + +As we use if/else statement when we have a condition which can take +one of the two states, we may have conditions which can take more than +two states. In such a scenario Python provides if/elif/else +statements. Let us take an example. We have a variable "a" which holds +integer values. We need to print "positive" if the value of a is +positive, "negative" if it is negative and "zero" if the value of the +variable "a" is 0. Let us use if/elif/else ladder for it. For the +purposes of testing our code let us assume that the value of a is -3:: + + a = -3 + + if a > 0: + print "positive" + elif a < 0: + print "negative" + else: + print "zero" + +This if/elif/else ladder is self explanatory. All the syntax and rules +as said for if/else statements hold. The only addition here is the +elif statement which can have another condition of its own. + +Here, exactly one block of code is executed and that block of code +corresponds to the condition which first evaluates to True. Even if +there is a situation where multiple conditions evaluate to True all +the subsequent conditions other than the first one which evaluates to +True are neglected. Consequently, the else block gets executed if and +only if all the conditions evaluate to False. + +Also, the else block in both if/else statement and if/elif/else is +optional. We can have a single if statement or just if/elif statements +without having else block at all. Also, there can be any number of +elif's within an if/elif/else ladder. For example + +{{{ Show slide for this }}} + + if user == 'admin': + # Do admin operations + elif user == 'moderator': + # Do moderator operations + elif user == 'client': + # Do customer operations + +{{{ end of slide switch to ipython }}} + +is completely valid. Note that there are multiple elif blocks and there +is no else block. + +In addition to these conditional statements, Python provides a very +convenient ternary conditional operator. Let us take the following +example where we read the marks data from a data file which is +obtained as a string as we read a file. The marks can be in the range +of 0 to 100 or 'AA' if the student is absent. In such a case to obtain +the marks as an integer we can use the ternary conditional +operator. Let us say the string score is stored in score_str +variable:: + + score_str = 'AA' + +Now let us use the ternary conditional operator:: + + score = int(score_str) if score_str != 'AA' else 0 + +This is just the if/else statement block which written in a more +convenient form and is very helpful when we have only one statement +for each block. This conditional statement effectively means as we +would have exactly specified in the English language which will be +like score is integer of score_str is score_str is not 'AA' otherwise +it is 0. This means that we make the scores of the students who were +absent for the exam 0. + +Moving on, there are certain situations where we will have to no +operations or statements within the block of code. For example, we +have a code where we are waiting for the keyboard input. If the user +enters "s" as the input we would perform some operation nothing +otherwise. In such cases "pass" statement comes very handy:: + + a = raw_input("Enter 'c' to calculate and exit, 'd' to display the existing + results exit and 'x' to exit and any other key to continue: ") + + if a == 'c': + # Calculate the marks and exit + elif a == 'd': + # Display the results and exit + elif a == 'x': + # Exit the program + else: + pass + +In this case "pass" statement acts as a place holder for the block of +code. It is equivalent to a null operation. It literally does +nothing. So "pass" statement can be used as a null operation +statement, or it can used as a place holder when the actual code +implementation for a particular block of code is not known yet but has +to be filled up later. + +{{{ Show summary slide }}} + +This brings us to the end of the tutorial session on conditional +statements in Python. In this tutorial session we learnt + + * What are conditional statements + * if/else statement + * if/elif/else statement + * Ternary conditional statement - C if X else Y + * and the "pass" statement + +{{{ 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 9d8fd5ea64b2 -r c6d31837cb06 conditionals/slides.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conditionals/slides.org Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,123 @@ +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] +#+BEAMER_FRAME_LEVEL: 1 + +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} +#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) +#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] + +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} + +#+TITLE: Accessing parts of arrays +#+AUTHOR: FOSSEE +#+EMAIL: +#+DATE: + +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc + +* Outline + - Manipulating one and multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slicing and striding on arrays to access chunks + - Read images into arrays and manipulations +* Sample Arrays + #+begin_src python + In []: A = array([12, 23, 34, 45, 56]) + + In []: 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]]) + + #+end_src +* Question 1 + Change the last column of ~C~ to zeroes. +* Solution 1 + #+begin_src python + In []: C[:, -1] = 0 + #+end_src +* Question 2 + Change ~A~ to ~[11, 12, 13, 14, 15]~. +* Solution 2 + #+begin_src python + In []: A[:] = [11, 12, 13, 14, 15] + #+end_src +* squares.png + #+begin_latex + \begin{center} + \includegraphics[scale=0.6]{squares} + \end{center} + #+end_latex +* Question 3 + - obtain ~[22, 23]~ from ~C~. + - obtain ~[11, 21, 31, 41]~ from ~C~. + - obtain ~[21, 31, 41, 0]~. +* Solution 3 + #+begin_src python + In []: C[1, 1:3] + In []: C[0:4, 0] + In []: C[1:5, 0] + #+end_src +* Question 4 + Obtain ~[[23, 24], [33, -34]]~ from ~C~ +* Solution 4 + #+begin_src python + In []: C[1:3, 2:4] + #+end_src +* Question 5 + Obtain the square in the center of the image +* Solution 5 + #+begin_src python + In []: imshow(I[75:225, 75:225]) + #+end_src +* Question 6 + Obtain the following + #+begin_src python + [[12, 0], [42, 0]] + [[12, 13, 14], [0, 0, 0]] + #+end_src + +* Solution 6 + #+begin_src python + In []: C[::3, 1::3] + In []: C[::4, 1:4] + #+end_src +* Summary + You should now be able to -- + - Manipulate 1D \& Multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slice and stride on arrays + - Read images into arrays and manipulate them. +* Thank you! +#+begin_latex + \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_latex + + diff -r 9d8fd5ea64b2 -r c6d31837cb06 conditionals/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conditionals/slides.tex Wed Oct 13 11:15:37 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 9d8fd5ea64b2 -r c6d31837cb06 getting-started-sagenotebook.rst --- a/getting-started-sagenotebook.rst Tue Oct 12 17:15:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,295 +0,0 @@ -Hello friends. Welcome to this spoken tutorial on Getting started with -sage and sage notebook. - -{{{ Show the slide containing the title }}} - -{{{ Show the slide containing the outline }}} - -In this tutorial, we will learn what Sage is, what is Sage notebook, -how to start and use the sage notebook. In the notebook we will be -specifically learning how to execute our code, how to write -annotations and other content, typesetting the content and how to use -the offline help available. - -{{{ Show the slide on what is Sage }}} - -To start with, What is Sage? Sage is a free, open-source mathematical -software. Sage can do a lot of math stuff for you including but not -limited to algebra, calculus, geometry, cryptography, graph theory -among other things. It can also be used as aid in teaching and -research in any of the areas that Sage supports. So let us start Sage -now - -{{{ Shift to terminal }}} - -We are assuming that you have Sage installed on your computer now. If -not please visit the page -http://sagemath.org/doc/tutorial/introduction.html#installation for -the tutorial on how to install Sage. Let us move on now. - -On the terminal type:: - - sage - -This should start a new Sage shell with the prompt sage: which looks -like this - -{{{ Show what is displayed on the terminal }}} - -So now we can type all the commands that Sage supports here. But Sage -comes bundled with a much much much more elegant tool called Sage -Notebook? What is Sage Notebook? Sage Notebook provides a web based -user interface to use Sage. So once we have a Sage notebook server up -and running all we want is a browser to access the Sage -functionality. For example there is an official instance of Sage -Notebook server running at http://sagenb.org You can visit that page, -create an account there and start using Sage! So all you need is just -a browser, a modern browser - -{{{ Intentional *cough* *cough* }}} - -to use Sage and nothing else! The Sage notebook also provides a -convenient way of sharing and publishing our work which is very handy -when we use Sage for research or for teaching. - -However we can also run our own instances of Sage notebook servers on -all the computers we have a local installation of Sage. To start the -notebook server just type:: - - notebook() - -on the Sage prompt. This will start the Sage Notebook server. If we -are starting the notebook server for the first time, we are prompted -to enter the password for the admin. Type the password and make a note -of it. After this Sage automatically starts a browser page for you -with the notebook opened. - -If it doesn't automatically start a browser page check if the Notebook -server started and there were no problems. If so open your browser and -in the address bar type the URL shown in the instructions upon running -the notebook command on the sage prompt. - -{{{ The notebook() command gives an instruction telling -Open your web browser to http://localhost:8000. Point towards it }}} - -In our case it is http://localhost:{{{ Tell whatever is shown }}} - -{{{ Show the browser with Sage notebook }}} - -If you are not logged in yet, it shows the Notebook home page and -textboxes to type the username and the password. You can use the -username 'admin' and the password you gave while starting the notebook -server for the first time. There are also links to recover forgotten -password and to create new accounts. - -{{{ If you are logged in tell that you are logged in, log out and show -what is said above for the login page }}} - -Once we are logged in with the admin account we can see the notebook -admin page. A notebook can contain a collection of Sage Notebook -worksheets. Worksheets are basically the working area. This is where -we enter all the Sage commands on the notebook. - -The admin page lists all the worksheets created. On the topmost part -of this page we have the links to various pages. - -{{{ Whenever you talk on an individual link point your mouse towards -the link. For each of the link go to the page and explain as below }}} - -The home link takes us to the admin home page. The published link -takes us to the page which lists all the published worksheets. The log -link has the complete log of all the actions we did on the -notebook. We have the settings link where can configure our notebook, -the notebook server, we can create and mangage accounts. We have a -link to help upon clicking opens a new window with the complete help -of Sage. The entire documentation of Sage is supplied with Sage for -offline reference and this help link is the way to get into it. Then -we can report bugs about Sage by clicking on Report a Problem link and -there is a link to sign out of the notebook. - -We can create a new worksheet by clicking New Worksheet link - -{{{ Click on the link }}} - -Sage prompts you for a name for the worksheet. Let us name the -worksheet as nbtutorial. Now we have our first worksheet which is -empty. - -A worksheet will contain a collection of cells. Every Sage command -must be entered in this cell. Cell is equivalent to the prompt on -console. When we create a new worksheet, to start with we will have -one empty cell. Let us try out some math here:: - - 2 + 2 - 57.1 ^ 100 - -The cap operator is used for exponentiation. If you observed carefully -we typed two commands but the output of only last command was -displayed. By default each cell displays the result of only the last -operation. We have to use print statement to display all the results -we want to be displayed. - -{{{ Demonstrate creating a new cell }}} - -Now to perform more operations we want more cells. So how do we create -a new cell? It is very simple. As we hover our mouse above or below -the existing cells we see a blue line, by clicking on this new line we -can create a new cell. - -We have a cell, we have typed some commands in it, but how do we -evaluate that cell? Pressing Shift along with Enter evaluates the -cell. Alternatively we can also click on the evaluate link to evaluate -the cell - -{{{ Evaluate the cell and demonstrate for both methods separately -}}}:: - - matrix([[1,2], [3,4]])^(-1) - -After we create many cells, we may want to move between the cells. To -move between the cells use Up and Down arrow keys. Also clicking on -the cell will let you edit that particular cell. - -{{{ Move between two cells created }}} - -To delete a cell, clear the contents of the cell and hit backspace - -{{{ Clear and demonstrate deleting the cell }}}:: - - Makes no sense - -If you want to add annotations in the worksheet itself on the blue -line that appears on hovering the mouse around the cell, Hold Shift -and click on the line. This creates a What You See Is What You Get -cell. - -{{{ Create a HTML editable cell }}} - -We can make our text here rich text. We can make it bold, Italics, we -can create bulleted and enumerated lists in this area:: - - This text contains both the **bold** text and also *italicised* - text. - It also contains bulleted list: - * Item 1 - * Item 2 - It also contains enumerate list: - 1. Item 1 - 2. Item 2 - -In the same cell we can display typeset math using the LaTeX like -syntax:: - - $\int_0^\infty e^{-x} \, dx$ - -We enclose the math to be typeset within $ and $ or $$ and $$ as in -LaTeX. - -We can also obtain help for a particular Sage command or function -within the worksheet itself by using a question mark following the -command:: - - sin? - -Evaluating this cell gives me the entire help for the sin function -inline on the worksheet itself. Similarly we can also look at the -source code of each command or function using double question mark:: - - matrix?? - -Sage notebook also provides the feature for autocompletion. To -autocomplete a command type first few unique characters and hit tab -key:: - - sudo - -To see all the commands starting with a specific name type those -characters and hit tab:: - - plo - -To list all the methods that are available for a certain variable or -a datatype we can use the variable name followed by the dot to access -the methods available on it and then hit tab:: - - s = 'Hello' - s.rep - -The output produced by each cell can be one of the three states. It -can be either the full output, or truncated output or hidden output. -The output area will display the error if the Sage code we wrote in -the cell did not successfully execute:: - - a, b = 10 - -{{{ Show the three states }}} - -The default output we obtained now is a truncated output. Clicking at -the left of the output area when the mouse pointer turns to hand gives -us the full output, clicking again makes the output hidden and it -cycles. - -Lastly, Sage supports a variety of languages and each cell on the -worksheet can contain code written in a specific language. It is -possible to instruct Sage to interpret the code in the language we -have written. This can be done by putting percentage sign(%) followed -by the name of the language. For example, to interpret the cell as -Python code we put:: - - %python - -as the first line in the cell. Similarly we have: %sh for shell -scripting, %fortran for Fortran, %gap for GAP and so on. Let us see -how this works. Say I have an integer. The type of the integer in -default Sage mode is -{{{ Read the output }}}:: - - a = 1 - type(a) - - Output: - -We see that Integers are Sage Integers. Now let us put %python as the -first line of the cell and execute the same code snippet:: - - %python - a = 1 - type(a) - - Output: - -Now we see that the integer is a Python integer. Why? Because now we -instructed Sage to interpret that cell as Python code. - -This brings us to the end of the tutorial on using Sage. We learnt -quite a lot about using the Notebook User Interface of Sage. We are -now confident that we can comfortably use the notebook to learn more -about Sage in the following tutorials. Let us summarize what we -learnt. In this session we learnt - - * What is Sage - * How to start Sage shell - * What is Sage notebook - * How to start the Sage notebook - * How to create accounts and start using the notebook - * How to create new worksheets - * The menus available on the notebook - * About cells in the worksheet - * Methods to evaluate the cell, create new cells, delete the cells - and navigate around the cells - * To make annotations in the worksheet - * Tab completions - * And embedding code of other scripting languages in the cells - -{{{ 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. -Thankyou - -.. Author : Madhu - Internal Reviewer 1 : [potential reviewer: Anoop] - Internal Reviewer 2 : [potential reviewer: Puneeth] - External Reviewer : - diff -r 9d8fd5ea64b2 -r c6d31837cb06 getting-started-sagenotebook/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-sagenotebook/questions.rst Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,28 @@ +Objective Questions +------------------- + +.. A mininum of 8 questions here (along with answers) + +1. Question 1 + + Answer: Answer 1 + + OR + + Answer:: + + answer code line 1 + answer code line 2 + answer code line 3 + +2. Question 2 +3. Question 3 + + +Larger Questions +---------------- + +.. A minimum of 2 questions here (along with answers) + +1. Question 1 +2. Question 2 diff -r 9d8fd5ea64b2 -r c6d31837cb06 getting-started-sagenotebook/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-sagenotebook/quickref.tex Wed Oct 13 11:15:37 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 9d8fd5ea64b2 -r c6d31837cb06 getting-started-sagenotebook/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-sagenotebook/script.rst Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,323 @@ +.. Objectives +.. ---------- + +.. Clearly state the objectives of the LO (along with RBT level) + +.. By the end of this tutorial, you should -- + +.. #. Know what Sage and Sage notebook are. +.. #. Be able to start a Sage shell or notebook +.. #. Be able to start using the notebook +.. #. Be able to create new worksheets +.. #. Know about the menu options available +.. #. Know about the cells in the worksheet +.. #. Be able to evaluate cells, create and delete cells, navigate them. +.. #. Be able to make annotations in the worksheet +.. #. Be able to use tab completion. +.. #. Be able to use code from other languages in the cells. + +.. Prerequisites +.. ------------- + +.. None. + +.. Author : Madhu + Internal Reviewer : + External Reviewer : + Checklist OK? : [2010-10-05] + + +Script +------ + +Hello friends. Welcome to this spoken tutorial on Getting started with +sage and sage notebook. + +{{{ Show the slide containing the title }}} + +{{{ Show the slide containing the outline }}} + +In this tutorial, we will learn what Sage is, what is Sage notebook, +how to start and use the sage notebook. In the notebook we will be +specifically learning how to execute our code, how to write +annotations and other content, typesetting the content and how to use +the offline help available. + +{{{ Show the slide on what is Sage }}} + +To start with, What is Sage? Sage is a free, open-source mathematical +software. Sage can do a lot of math stuff for you including but not +limited to algebra, calculus, geometry, cryptography, graph theory +among other things. It can also be used as aid in teaching and +research in any of the areas that Sage supports. So let us start Sage +now + +{{{ Shift to terminal }}} + +We are assuming that you have Sage installed on your computer now. If +not please visit the page +http://sagemath.org/doc/tutorial/introduction.html#installation for +the tutorial on how to install Sage. Let us move on now. + +On the terminal type:: + + sage + +This should start a new Sage shell with the prompt sage: which looks +like this + +{{{ Show what is displayed on the terminal }}} + +So now we can type all the commands that Sage supports here. But Sage +comes bundled with a much much much more elegant tool called Sage +Notebook? What is Sage Notebook? Sage Notebook provides a web based +user interface to use Sage. So once we have a Sage notebook server up +and running all we want is a browser to access the Sage +functionality. For example there is an official instance of Sage +Notebook server running at http://sagenb.org You can visit that page, +create an account there and start using Sage! So all you need is just +a browser, a modern browser + +{{{ Intentional *cough* *cough* }}} + +to use Sage and nothing else! The Sage notebook also provides a +convenient way of sharing and publishing our work which is very handy +when we use Sage for research or for teaching. + +However we can also run our own instances of Sage notebook servers on +all the computers we have a local installation of Sage. To start the +notebook server just type:: + + notebook() + +on the Sage prompt. This will start the Sage Notebook server. If we +are starting the notebook server for the first time, we are prompted +to enter the password for the admin. Type the password and make a note +of it. After this Sage automatically starts a browser page for you +with the notebook opened. + +If it doesn't automatically start a browser page check if the Notebook +server started and there were no problems. If so open your browser and +in the address bar type the URL shown in the instructions upon running +the notebook command on the sage prompt. + +{{{ The notebook() command gives an instruction telling +Open your web browser to http://localhost:8000. Point towards it }}} + +In our case it is http://localhost:{{{ Tell whatever is shown }}} + +{{{ Show the browser with Sage notebook }}} + +If you are not logged in yet, it shows the Notebook home page and +textboxes to type the username and the password. You can use the +username 'admin' and the password you gave while starting the notebook +server for the first time. There are also links to recover forgotten +password and to create new accounts. + +{{{ If you are logged in tell that you are logged in, log out and show +what is said above for the login page }}} + +Once we are logged in with the admin account we can see the notebook +admin page. A notebook can contain a collection of Sage Notebook +worksheets. Worksheets are basically the working area. This is where +we enter all the Sage commands on the notebook. + +The admin page lists all the worksheets created. On the topmost part +of this page we have the links to various pages. + +{{{ Whenever you talk on an individual link point your mouse towards +the link. For each of the link go to the page and explain as below }}} + +The home link takes us to the admin home page. The published link +takes us to the page which lists all the published worksheets. The log +link has the complete log of all the actions we did on the +notebook. We have the settings link where can configure our notebook, +the notebook server, we can create and mangage accounts. We have a +link to help upon clicking opens a new window with the complete help +of Sage. The entire documentation of Sage is supplied with Sage for +offline reference and this help link is the way to get into it. Then +we can report bugs about Sage by clicking on Report a Problem link and +there is a link to sign out of the notebook. + +We can create a new worksheet by clicking New Worksheet link + +{{{ Click on the link }}} + +Sage prompts you for a name for the worksheet. Let us name the +worksheet as nbtutorial. Now we have our first worksheet which is +empty. + +A worksheet will contain a collection of cells. Every Sage command +must be entered in this cell. Cell is equivalent to the prompt on +console. When we create a new worksheet, to start with we will have +one empty cell. Let us try out some math here:: + + 2 + 2 + 57.1 ^ 100 + +The cap operator is used for exponentiation. If you observed carefully +we typed two commands but the output of only last command was +displayed. By default each cell displays the result of only the last +operation. We have to use print statement to display all the results +we want to be displayed. + +{{{ Demonstrate creating a new cell }}} + +Now to perform more operations we want more cells. So how do we create +a new cell? It is very simple. As we hover our mouse above or below +the existing cells we see a blue line, by clicking on this new line we +can create a new cell. + +We have a cell, we have typed some commands in it, but how do we +evaluate that cell? Pressing Shift along with Enter evaluates the +cell. Alternatively we can also click on the evaluate link to evaluate +the cell + +{{{ Evaluate the cell and demonstrate for both methods separately +}}}:: + + matrix([[1,2], [3,4]])^(-1) + +After we create many cells, we may want to move between the cells. To +move between the cells use Up and Down arrow keys. Also clicking on +the cell will let you edit that particular cell. + +{{{ Move between two cells created }}} + +To delete a cell, clear the contents of the cell and hit backspace + +{{{ Clear and demonstrate deleting the cell }}}:: + + Makes no sense + +If you want to add annotations in the worksheet itself on the blue +line that appears on hovering the mouse around the cell, Hold Shift +and click on the line. This creates a What You See Is What You Get +cell. + +{{{ Create a HTML editable cell }}} + +We can make our text here rich text. We can make it bold, Italics, we +can create bulleted and enumerated lists in this area:: + + This text contains both the **bold** text and also *italicised* + text. + It also contains bulleted list: + * Item 1 + * Item 2 + It also contains enumerate list: + 1. Item 1 + 2. Item 2 + +In the same cell we can display typeset math using the LaTeX like +syntax:: + + $\int_0^\infty e^{-x} \, dx$ + +We enclose the math to be typeset within $ and $ or $$ and $$ as in +LaTeX. + +We can also obtain help for a particular Sage command or function +within the worksheet itself by using a question mark following the +command:: + + sin? + +Evaluating this cell gives me the entire help for the sin function +inline on the worksheet itself. Similarly we can also look at the +source code of each command or function using double question mark:: + + matrix?? + +Sage notebook also provides the feature for autocompletion. To +autocomplete a command type first few unique characters and hit tab +key:: + + sudo + +To see all the commands starting with a specific name type those +characters and hit tab:: + + plo + +To list all the methods that are available for a certain variable or +a datatype we can use the variable name followed by the dot to access +the methods available on it and then hit tab:: + + s = 'Hello' + s.rep + +The output produced by each cell can be one of the three states. It +can be either the full output, or truncated output or hidden output. +The output area will display the error if the Sage code we wrote in +the cell did not successfully execute:: + + a, b = 10 + +{{{ Show the three states }}} + +The default output we obtained now is a truncated output. Clicking at +the left of the output area when the mouse pointer turns to hand gives +us the full output, clicking again makes the output hidden and it +cycles. + +Lastly, Sage supports a variety of languages and each cell on the +worksheet can contain code written in a specific language. It is +possible to instruct Sage to interpret the code in the language we +have written. This can be done by putting percentage sign(%) followed +by the name of the language. For example, to interpret the cell as +Python code we put:: + + %python + +as the first line in the cell. Similarly we have: %sh for shell +scripting, %fortran for Fortran, %gap for GAP and so on. Let us see +how this works. Say I have an integer. The type of the integer in +default Sage mode is +{{{ Read the output }}}:: + + a = 1 + type(a) + + Output: + +We see that Integers are Sage Integers. Now let us put %python as the +first line of the cell and execute the same code snippet:: + + %python + a = 1 + type(a) + + Output: + +Now we see that the integer is a Python integer. Why? Because now we +instructed Sage to interpret that cell as Python code. + +This brings us to the end of the tutorial on using Sage. We learnt +quite a lot about using the Notebook User Interface of Sage. We are +now confident that we can comfortably use the notebook to learn more +about Sage in the following tutorials. Let us summarize what we +learnt. In this session we learnt + + * What is Sage + * How to start Sage shell + * What is Sage notebook + * How to start the Sage notebook + * How to create accounts and start using the notebook + * How to create new worksheets + * The menus available on the notebook + * About cells in the worksheet + * Methods to evaluate the cell, create new cells, delete the cells + and navigate around the cells + * To make annotations in the worksheet + * Tab completions + * And embedding code of other scripting languages in the cells + +{{{ 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 9d8fd5ea64b2 -r c6d31837cb06 getting-started-sagenotebook/slides.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-sagenotebook/slides.org Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,123 @@ +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] +#+BEAMER_FRAME_LEVEL: 1 + +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} +#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) +#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] + +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} + +#+TITLE: Accessing parts of arrays +#+AUTHOR: FOSSEE +#+EMAIL: +#+DATE: + +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc + +* Outline + - Manipulating one and multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slicing and striding on arrays to access chunks + - Read images into arrays and manipulations +* Sample Arrays + #+begin_src python + In []: A = array([12, 23, 34, 45, 56]) + + In []: 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]]) + + #+end_src +* Question 1 + Change the last column of ~C~ to zeroes. +* Solution 1 + #+begin_src python + In []: C[:, -1] = 0 + #+end_src +* Question 2 + Change ~A~ to ~[11, 12, 13, 14, 15]~. +* Solution 2 + #+begin_src python + In []: A[:] = [11, 12, 13, 14, 15] + #+end_src +* squares.png + #+begin_latex + \begin{center} + \includegraphics[scale=0.6]{squares} + \end{center} + #+end_latex +* Question 3 + - obtain ~[22, 23]~ from ~C~. + - obtain ~[11, 21, 31, 41]~ from ~C~. + - obtain ~[21, 31, 41, 0]~. +* Solution 3 + #+begin_src python + In []: C[1, 1:3] + In []: C[0:4, 0] + In []: C[1:5, 0] + #+end_src +* Question 4 + Obtain ~[[23, 24], [33, -34]]~ from ~C~ +* Solution 4 + #+begin_src python + In []: C[1:3, 2:4] + #+end_src +* Question 5 + Obtain the square in the center of the image +* Solution 5 + #+begin_src python + In []: imshow(I[75:225, 75:225]) + #+end_src +* Question 6 + Obtain the following + #+begin_src python + [[12, 0], [42, 0]] + [[12, 13, 14], [0, 0, 0]] + #+end_src + +* Solution 6 + #+begin_src python + In []: C[::3, 1::3] + In []: C[::4, 1:4] + #+end_src +* Summary + You should now be able to -- + - Manipulate 1D \& Multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slice and stride on arrays + - Read images into arrays and manipulate them. +* Thank you! +#+begin_latex + \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_latex + + diff -r 9d8fd5ea64b2 -r c6d31837cb06 getting-started-sagenotebook/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-sagenotebook/slides.tex Wed Oct 13 11:15:37 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 9d8fd5ea64b2 -r c6d31837cb06 getting-started-strings.rst --- a/getting-started-strings.rst Tue Oct 12 17:15:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +0,0 @@ -Hello friends. Welcome to this spoken tutorial on Getting started with -strings. - -{{{ Show the slide containing the title }}} - -{{{ Show the slide containing the outline }}} - -In this tutorial, we will learn what do we actually mean by strings in -python, how python supports the use of strings. We will also learn -some of the operations that can be performed on strings. - -{{{ Shift to terminal and start ipython }}} - -To begin with let us start ipython, by typing:: - - ipython - -on the terminal - -So what are strings? In Python anything within either single quotes -or double quotes or triple single quotes or triple double quotes are -strings. This is true whatsoever, even if there is only one character -within the quotes - -{{{ Type in ipython the following and read them as you type }}}:: - - 'This is a string' - "This is a string too' - '''This is a string as well''' - """This is also a string""" - 'p' - -Having more than one control character to define strings come as very -handy when one of the control characters itself is part of the -string. For example:: - - "Python's string manipulation functions are very useful" - -In this case we use single quote for apostrophe. If we had only single -quote to define strings we should have a clumsy way of escaping the -single quote character to make it part of the string. Hence this is a -very handy feature. - -The triple quoted strings let us define multi-lines strings without -using any escaping. Everything within the triple quotes is a single -string no matter how many lines it extends:: - - """Having more than one control character to define - strings come as very handy when one of the control - characters itself is part of the string.""" - -We can assign this string to any variable:: - - a = 'Hello, World!' - -Now 'a' is a string variable. String is a collection of characters. In -addition string is an immutable collection. So all the operations that -are applicable to any other immutable collection in Python works on -string as well. So we can add two strings:: - - a = 'Hello' - b = 'World' - c = a + ', ' + b + '!' - -We can add string variables as well as the strings themselves all in -the same statement. The addition operation performs the concatenation -of two strings. - -Similarly we can multiply a string with an integer:: - - a = 'Hello' - a * 5 - -gives another string in which the original string 'Hello' is repeated -5 times. - -Since strings are collections we can access individual items in the -string using the subscripts:: - - a[0] - -gives us the first character in the string. The indexing starts from 0 -for the first character up to n-1 for the last character. We can -access the strings from the end using negative indices:: - - a[-2] - -gives us second element from the end of the string - -Let us attempt to change one of the characters in a string:: - - a = 'hello' - a[0] = 'H' - -As said earlier, strings are immutable. We cannot manipulate the -string. Although there are some methods which let us to manipulate the -strings. We will look at them in the advanced session on strings. In -addition to the methods that let us manipulate the strings we have -methods like split which lets us break the string on the specified -separator, the join method which lets us combine the list of strings -into a single string based on the specified separator. - -{{{ Show summary slide }}} - -This brings us to the end of another session. In this tutorial session -we learnt - - * How to define strings - * Different types of defining a string - * String concatenation and repeatition - * Accessing individual elements of the string - * Immutability of strings - -{{{ 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. -Thankyou - -.. Author : Madhu - Internal Reviewer 1 : [potential reviewer: Nishanth] - Internal Reviewer 2 : [potential reviewer: Amit] - External Reviewer : - diff -r 9d8fd5ea64b2 -r c6d31837cb06 getting-started-strings/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-strings/questions.rst Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,80 @@ +Objective Questions +------------------- + +.. A mininum of 8 questions here (along with answers) + +1. List the type of quotes that can be used to define strings. + + Answer: 'single quotes', "double quotes", + '''triple single quotes''' + """triple double quotes""" + +#. Given the strings ``s`` and ``S``, ``s='Hello World'`` and + ``S="Hello World``. s and S are different strings. True or False? + +#. What is the output of:: + + s = 'It's all here' + + Answer: ``SyntaxError`` + +#. Write code to assign s, the string ``' is called the apostrophe`` + + Answer: ``s = "`is called the apostrophe"`` + +#. Given strings s and t, ``s = "Hello"`` and ``t = "World"``. What is + the output of s + t? + + Answer: HelloWorld + +#. Given strings s and t, ``s = "Hello"`` and ``t = "World"`` and an + integer r, ``r = 2``. What is the output of s * r + s * t? + + Answer: HelloHelloWorldWorld + +#. Given strings s and t, ``s = "Hello"`` and ``t = "World"`` and an + integer r, ``r = 2``. What is the output of s * 'r' ? + + Answer: TypeError - can't multiply a sequence by non-int + +#. Given the string ``s = "Hello"``, we wish to change it to + ``hello``. what is the result of:: + + s[0] = 'h' + + Answer: TypeError - 'str' object does not support item assignment. + +#. Given the string ``s = "Hello"``, we wish to change it to + ``hello``. what is the result of:: + + s = "hello" + + Answer: s is changed to "hello" + +#. Which type of string can be written in multiple lines, with line + breaks. (Note: more than one answer may be correct.) + + #. triple double quoted strings + #. single quoted strings + #. double quoted strings + #. triple single quoted strings + + Answer: triple double quoted strings and triple single quoted strings + +Larger Questions +---------------- + +.. A minimum of 2 questions here (along with answers) + +1. Given the string s, ``s = F.R.I.E.N.D.S``, obtain the string + "FRIENDS". + + Answer:: + + s = s[0] + s[2] + s[4] + s[6] + s[8] + s[10] + s[12] + +2. Assign the string ``Today's Quote: "Don't believe in any quote, + including this."`` to the variable ``quote``. + + Answer: + quote = """Today's Quote: "Don't believe in any quote, including this.""" diff -r 9d8fd5ea64b2 -r c6d31837cb06 getting-started-strings/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-strings/quickref.tex Wed Oct 13 11:15:37 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 9d8fd5ea64b2 -r c6d31837cb06 getting-started-strings/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-strings/script.rst Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,145 @@ +.. Objectives +.. ---------- + +.. At the end of this tutorial, you should know -- + +.. 1. How to define strings +.. #. Different ways of defining a string +.. #. How to concatenate strings +.. #. How to print a string repeatedly +.. #. Accessing individual elements of the string +.. #. Immutability of strings + +.. Prerequisites +.. ------------- + +.. 1. getting started with ipython + +.. Author : Madhu + Internal Reviewer : + External Reviewer : + Checklist OK? : [2010-10-05] + +Script +------ + +{{{ Show the slide containing the title }}} + +Hello friends. Welcome to this spoken tutorial on Getting started with +strings. + +{{{ Show the slide containing the outline }}} + +In this tutorial, we will learn what do we actually mean by strings in +python, how python supports the use of strings. We will also learn +some of the operations that can be performed on strings. + +{{{ Shift to terminal and start ipython }}} + +To begin with let us start ipython, by typing:: + + ipython + +on the terminal + +So what are strings? In Python anything within either single quotes +or double quotes or triple single quotes or triple double quotes are +strings. This is true whatsoever, even if there is only one character +within the quotes + +{{{ Type in ipython the following and read them as you type }}}:: + + 'This is a string' + "This is a string too' + '''This is a string as well''' + """This is also a string""" + 'p' + +Having more than one control character to define strings come as very +handy when one of the control characters itself is part of the +string. For example:: + + "Python's string manipulation functions are very useful" + +In this case we use single quote for apostrophe. If we had only single +quote to define strings we should have a clumsy way of escaping the +single quote character to make it part of the string. Hence this is a +very handy feature. + +The triple quoted strings let us define multi-lines strings without +using any escaping. Everything within the triple quotes is a single +string no matter how many lines it extends:: + + """Having more than one control character to define + strings come as very handy when one of the control + characters itself is part of the string.""" + +We can assign this string to any variable:: + + a = 'Hello, World!' + +Now 'a' is a string variable. String is a collection of characters. In +addition string is an immutable collection. So all the operations that +are applicable to any other immutable collection in Python works on +string as well. So we can add two strings:: + + a = 'Hello' + b = 'World' + c = a + ', ' + b + '!' + +We can add string variables as well as the strings themselves all in +the same statement. The addition operation performs the concatenation +of two strings. + +Similarly we can multiply a string with an integer:: + + a = 'Hello' + a * 5 + +gives another string in which the original string 'Hello' is repeated +5 times. + +Since strings are collections we can access individual items in the +string using the subscripts:: + + a[0] + +gives us the first character in the string. The indexing starts from 0 +for the first character up to n-1 for the last character. We can +access the strings from the end using negative indices:: + + a[-2] + +gives us second element from the end of the string + +Let us attempt to change one of the characters in a string:: + + a = 'hello' + a[0] = 'H' + +As said earlier, strings are immutable. We cannot manipulate the +string. Although there are some methods which let us to manipulate the +strings. We will look at them in the advanced session on strings. In +addition to the methods that let us manipulate the strings we have +methods like split which lets us break the string on the specified +separator, the join method which lets us combine the list of strings +into a single string based on the specified separator. + +{{{ Show summary slide }}} + +This brings us to the end of another session. In this tutorial session +we learnt + + * How to define strings + * Different ways of defining a string + * String concatenation and repeatition + * Accessing individual elements of the string + * Immutability of strings + +{{{ 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 9d8fd5ea64b2 -r c6d31837cb06 getting-started-strings/slides.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-strings/slides.org Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,123 @@ +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] +#+BEAMER_FRAME_LEVEL: 1 + +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} +#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) +#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] + +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} + +#+TITLE: Accessing parts of arrays +#+AUTHOR: FOSSEE +#+EMAIL: +#+DATE: + +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc + +* Outline + - Manipulating one and multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slicing and striding on arrays to access chunks + - Read images into arrays and manipulations +* Sample Arrays + #+begin_src python + In []: A = array([12, 23, 34, 45, 56]) + + In []: 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]]) + + #+end_src +* Question 1 + Change the last column of ~C~ to zeroes. +* Solution 1 + #+begin_src python + In []: C[:, -1] = 0 + #+end_src +* Question 2 + Change ~A~ to ~[11, 12, 13, 14, 15]~. +* Solution 2 + #+begin_src python + In []: A[:] = [11, 12, 13, 14, 15] + #+end_src +* squares.png + #+begin_latex + \begin{center} + \includegraphics[scale=0.6]{squares} + \end{center} + #+end_latex +* Question 3 + - obtain ~[22, 23]~ from ~C~. + - obtain ~[11, 21, 31, 41]~ from ~C~. + - obtain ~[21, 31, 41, 0]~. +* Solution 3 + #+begin_src python + In []: C[1, 1:3] + In []: C[0:4, 0] + In []: C[1:5, 0] + #+end_src +* Question 4 + Obtain ~[[23, 24], [33, -34]]~ from ~C~ +* Solution 4 + #+begin_src python + In []: C[1:3, 2:4] + #+end_src +* Question 5 + Obtain the square in the center of the image +* Solution 5 + #+begin_src python + In []: imshow(I[75:225, 75:225]) + #+end_src +* Question 6 + Obtain the following + #+begin_src python + [[12, 0], [42, 0]] + [[12, 13, 14], [0, 0, 0]] + #+end_src + +* Solution 6 + #+begin_src python + In []: C[::3, 1::3] + In []: C[::4, 1:4] + #+end_src +* Summary + You should now be able to -- + - Manipulate 1D \& Multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slice and stride on arrays + - Read images into arrays and manipulate them. +* Thank you! +#+begin_latex + \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_latex + + diff -r 9d8fd5ea64b2 -r c6d31837cb06 getting-started-strings/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-strings/slides.tex Wed Oct 13 11:15:37 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 9d8fd5ea64b2 -r c6d31837cb06 manipulating-lists.rst --- a/manipulating-lists.rst Tue Oct 12 17:15:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,180 +0,0 @@ -Hello friends. Welcome to this spoken tutorial on Getting started with -strings. - -{{{ Show the slide containing the title }}} - -{{{ Show the slide containing the outline }}} - -We have already learnt a lot about Lists in Python. In this tutorial, -we will learn more about advanced features of Lists in Python. We will -see in detail how to concatenate two lists, slicing and striding of -lists, methods to sort and reverse the list. - -{{{ Shift to terminal and start ipython }}} - -To begin with let us start ipython, by typing:: - - ipython - -on the terminal - -We already know what Lists are in Python, how to access individual -elements in the list and some of the functions that can be run on the -lists like max, min, sum len and so on. Now let us learn some of the -basic operations that can be performed on Lists. - -We already know how to access individual elements in a List. But what -if we have a scenario where we need to get a part of the entire list -or what we call as a slice of the list? Python supports slicing on -lists. Let us say I have the list:: - - primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] - -To obtain the all the primes between 10 and 20 from the above list of -primes we say:: - - primes[4:8] - -This gives us all the elements in the list starting from the element -with the index 4 which is 11 in our list upto the element with index 8 -in the list but not including the eigth element. So we obtain a slice -starting from 11 upto 19th. It is a very important to remember that -when ever we specify a range of elements in Python the start index is -included and end index is not included. So in the above case, 11 which -was the element with the index 4 was included but 23 which was the -element with index 8 was exluded. - -Generalizing, we can obtain a slice of the list "p" from the index -"start" upto the index "end" but excluding "end" with the following -syntax - -{{{ Show the slide containing p[start:stop] }}} - -By default the slice fetches all the elements between start and stop -including start but not stop. So as to say we obtain all the elements -between start and stop in steps of one. Python also provides us the -functionality to specify the steps in which the slice must be -obtained. Say we have:: - - num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] - -If we want to obtain all the odd numbers less than 10 from the list -"num" we have to start from element with index 1 upto the index 10 in -steps of 2:: - - num[1:10:2] - -So if we don't specify the step it is by default 1. Similary there are -default values for start and stop indices as well. If we don't specify -the start index it is implicitly taken as the first element of the -list:: - - num[:10] - -This gives us all the elements from the beginning upto the 10th -element but not including the 10th element in the list "num". Similary -if the stop index is not specified it is implicitly assumed to be the -end of the list, including the last element of the list:: - - num[10:] - -gives all the elements starting from the 10th element in the list -"num" upto the final element including that last element. Now:: - - num[::2] - -gives us all the even numbers in the list "num". - -The other basic operation that we can perform on list is concatenation -of two or more lists. We can combine two lists by using the "plus" -operator. Say we have - -{{{ Read as you type }}}:: - - a = [1, 2, 3, 4] - b = [4, 5, 6, 7] - a + b - -When we concatenate lists using the "plus" operator we get a new -list. We can store this list in a new variable:: - - c = a + b - c - -It is important to observe that the "plus" operator always returns a -new list without touching anything in the existing lists which are the -operands of the concatenation operation. - -We know that list is a collection of data. Whenever we have a -collection we run into situations where we want to start the -collection. Lists support sort method which sorts the list inplace:: - - a = [5, 1, 6, 7, 7, 10] - a.sort() - -Now the contents of the list "a" will be:: - - a - [1, 5, 6, 7, 7, 10] - -Since the sort method sorts the list inplace the original list we had -is overwritten or replaced. We have no way to obtain the original list -back. One way to avoid this is to keep a copy of the original list in -another variable and run the sort method on the list. However Python -also provides a built-in function called sorted which sorts the list -which is passed as an argument to it and returns a new sorted list:: - - a = [5, 1, 6, 7, 7, 10] - sorted(a) - -We can store this sorted list another list variable:: - - sa = sorted(a) - -Similarly to perform certain operations on the list we would like to -reverse the list. Python provides reverse method which again reverses -the list inplace:: - - a = [1, 2, 3, 4, 5] - a.reverse() - -reverses the list "a" and stores the reversed list inplace i.e. in "a" -itself. Lets see the list "a":: - - a - [5, 4, 3, 2, 1] - -But again the original list is lost. If we want to obtain the reverse -of a list keeping the original list intact we can use the Python -built-in function reversed. reversed function returns a new list which -is the reverse of the list which was passed as the argument to the -reversed function:: - - a = [1, 2, 3, 4, 5] - reversed(a) - -We can also store this new reversed list in another list variable. - -{{{ Show summary slide }}} - -This brings us to the end of another session. In this tutorial session -we learnt - - * How to define strings - * Different types of defining a string - * String concatenation and repeatition - * Accessing individual elements of the string - * Immutability of strings - -{{{ 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. -Thankyou - -.. Author : Madhu - Internal Reviewer 1 : [potential reviewer: Nishanth] - Internal Reviewer 2 : [potential reviewer: Amit] - External Reviewer : - diff -r 9d8fd5ea64b2 -r c6d31837cb06 manipulating-lists/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manipulating-lists/questions.rst Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,72 @@ +Objective Questions +------------------- + +.. A mininum of 8 questions here (along with answers) + +1. Given the list primes, ``primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, + 29]``, How do you obtain the last 4 primes? + + Answer: primes[-4:] + +#. Given the list primes, ``primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, + 29]``, What is the output of ``primes[::5]``? + + Answer: ``[2, 13]`` + +#. Given a list, p, of unknown length, obtain the first 3 (or all, if + there are fewer) characters of it. + + Answer: p[:3] + +#. The method ``reverse`` reverses a list in-place. True or False? + + Answer: True + +#. ``reversed`` function reverses a list in-place. True or False? + + Answer: False + +#. Given the list ``p = [1, 2, 3]``. p[4] produces an IndexError. True + or False? + + Answer: True + +#. Given the list ``p = [1, 2, 3]``. p[:4] produces an IndexError. True + or False? + + Answer: False + +#. Given the list primes, ``primes = [2, 3, 5, 7, 11]``, What is the + output of ``primes[::-1]``? + + Answer: [11, 7, 5, 3, 2] + +#. Given the list primes, ``primes = [2, 3, 5, 7, 11]``, What is the + output of ``primes[::-3]``? + + Answer: [11, 3] + + +Larger Questions +---------------- + +.. A minimum of 2 questions here (along with answers) + +#. Given a list p. Append it's reverse to itself. + + Answer:: + + p = p + reversed(p) + + +#. Marks is a list containing the roll numbers of students followed by + marks. [This is not a recommended way to hold the marks details, + but the teacher knows only so much Python!] Now she wants to get + the average of the marks. Help her do it. + + Answer:: + + marks = [1, 9, 2, 8, 3, 3, 4, 10, 5, 2] + average = sum(marks[1::2])/len(marks[1::2]) + + diff -r 9d8fd5ea64b2 -r c6d31837cb06 manipulating-lists/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manipulating-lists/quickref.tex Wed Oct 13 11:15:37 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 9d8fd5ea64b2 -r c6d31837cb06 manipulating-lists/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manipulating-lists/script.rst Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,196 @@ +.. Objectives +.. ---------- + +.. Clearly state the objectives of the LO (along with RBT level) + +.. Prerequisites +.. ------------- + +.. 1. getting started with lists +.. 2. +.. 3. + +.. Author : Madhu + Internal Reviewer : + External Reviewer : + Checklist OK? : [2010-10-05] + +Script +------ + +{{{ Show the slide containing the title }}} + +Hello friends. Welcome to this spoken tutorial on Manipulating Lists. + + +{{{ Show the slide containing the outline }}} + +We have already learnt a lot about Lists in Python. In this tutorial, +we will learn more about advanced features of Lists in Python. We will +see in detail how to concatenate two lists, slicing and striding of +lists, methods to sort and reverse the list. + +{{{ Shift to terminal and start ipython }}} + +To begin with let us start ipython, by typing:: + + ipython + +on the terminal + +We already know what Lists are in Python, how to access individual +elements in the list and some of the functions that can be run on the +lists like max, min, sum len and so on. Now let us learn some of the +basic operations that can be performed on Lists. + +We already know how to access individual elements in a List. But what +if we have a scenario where we need to get a part of the entire list +or what we call as a slice of the list? Python supports slicing on +lists. Let us say I have the list:: + + primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] + +To obtain the all the primes between 10 and 20 from the above list of +primes we say:: + + primes[4:8] + +This gives us all the elements in the list starting from the element +with the index 4 which is 11 in our list upto the element with index 8 +in the list but not including the eigth element. So we obtain a slice +starting from 11 upto 19th. It is a very important to remember that +when ever we specify a range of elements in Python the start index is +included and end index is not included. So in the above case, 11 which +was the element with the index 4 was included but 23 which was the +element with index 8 was excluded. + +Generalizing, we can obtain a slice of the list "p" from the index +"start" upto the index "end" but excluding "end" with the following +syntax + +{{{ Show the slide containing p[start:stop] }}} + +By default the slice fetches all the elements between start and stop +including start but not stop. So as to say we obtain all the elements +between start and stop in steps of one. Python also provides us the +functionality to specify the steps in which the slice must be +obtained. Say we have:: + + num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] + +If we want to obtain all the odd numbers less than 10 from the list +"num" we have to start from element with index 1 upto the index 10 in +steps of 2:: + + num[1:10:2] + +So if we don't specify the step it is by default 1. Similary there are +default values for start and stop indices as well. If we don't specify +the start index it is implicitly taken as the first element of the +list:: + + num[:10] + +This gives us all the elements from the beginning upto the 10th +element but not including the 10th element in the list "num". Similary +if the stop index is not specified it is implicitly assumed to be the +end of the list, including the last element of the list:: + + num[10:] + +gives all the elements starting from the 10th element in the list +"num" upto the final element including that last element. Now:: + + num[::2] + +gives us all the even numbers in the list "num". + +The other basic operation that we can perform on list is concatenation +of two or more lists. We can combine two lists by using the "plus" +operator. Say we have + +{{{ Read as you type }}}:: + + a = [1, 2, 3, 4] + b = [4, 5, 6, 7] + a + b + +When we concatenate lists using the "plus" operator we get a new +list. We can store this list in a new variable:: + + c = a + b + c + +It is important to observe that the "plus" operator always returns a +new list without touching anything in the existing lists which are the +operands of the concatenation operation. + +We know that list is a collection of data. Whenever we have a +collection we run into situations where we want to start the +collection. Lists support sort method which sorts the list inplace:: + + a = [5, 1, 6, 7, 7, 10] + a.sort() + +Now the contents of the list "a" will be:: + + a + [1, 5, 6, 7, 7, 10] + +Since the sort method sorts the list inplace the original list we had +is overwritten or replaced. We have no way to obtain the original list +back. One way to avoid this is to keep a copy of the original list in +another variable and run the sort method on the list. However Python +also provides a built-in function called sorted which sorts the list +which is passed as an argument to it and returns a new sorted list:: + + a = [5, 1, 6, 7, 7, 10] + sorted(a) + +We can store this sorted list another list variable:: + + sa = sorted(a) + +Similarly to perform certain operations on the list we would like to +reverse the list. Python provides reverse method which again reverses +the list inplace:: + + a = [1, 2, 3, 4, 5] + a.reverse() + +reverses the list "a" and stores the reversed list inplace i.e. in "a" +itself. Lets see the list "a":: + + a + [5, 4, 3, 2, 1] + +But again the original list is lost. If we want to obtain the reverse +of a list keeping the original list intact we can use the Python +built-in function reversed. reversed function returns a new list which +is the reverse of the list which was passed as the argument to the +reversed function:: + + a = [1, 2, 3, 4, 5] + reversed(a) + +We can also store this new reversed list in another list variable. + +{{{ Show summary slide }}} + +This brings us to the end of another session. In this tutorial session +we learnt + + * How to define strings + * Different types of defining a string + * String concatenation and repeatition + * Accessing individual elements of the string + * Immutability of strings + +{{{ 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 9d8fd5ea64b2 -r c6d31837cb06 manipulating-lists/slides.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manipulating-lists/slides.org Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,123 @@ +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] +#+BEAMER_FRAME_LEVEL: 1 + +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} +#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) +#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] + +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} + +#+TITLE: Accessing parts of arrays +#+AUTHOR: FOSSEE +#+EMAIL: +#+DATE: + +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc + +* Outline + - Manipulating one and multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slicing and striding on arrays to access chunks + - Read images into arrays and manipulations +* Sample Arrays + #+begin_src python + In []: A = array([12, 23, 34, 45, 56]) + + In []: 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]]) + + #+end_src +* Question 1 + Change the last column of ~C~ to zeroes. +* Solution 1 + #+begin_src python + In []: C[:, -1] = 0 + #+end_src +* Question 2 + Change ~A~ to ~[11, 12, 13, 14, 15]~. +* Solution 2 + #+begin_src python + In []: A[:] = [11, 12, 13, 14, 15] + #+end_src +* squares.png + #+begin_latex + \begin{center} + \includegraphics[scale=0.6]{squares} + \end{center} + #+end_latex +* Question 3 + - obtain ~[22, 23]~ from ~C~. + - obtain ~[11, 21, 31, 41]~ from ~C~. + - obtain ~[21, 31, 41, 0]~. +* Solution 3 + #+begin_src python + In []: C[1, 1:3] + In []: C[0:4, 0] + In []: C[1:5, 0] + #+end_src +* Question 4 + Obtain ~[[23, 24], [33, -34]]~ from ~C~ +* Solution 4 + #+begin_src python + In []: C[1:3, 2:4] + #+end_src +* Question 5 + Obtain the square in the center of the image +* Solution 5 + #+begin_src python + In []: imshow(I[75:225, 75:225]) + #+end_src +* Question 6 + Obtain the following + #+begin_src python + [[12, 0], [42, 0]] + [[12, 13, 14], [0, 0, 0]] + #+end_src + +* Solution 6 + #+begin_src python + In []: C[::3, 1::3] + In []: C[::4, 1:4] + #+end_src +* Summary + You should now be able to -- + - Manipulate 1D \& Multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slice and stride on arrays + - Read images into arrays and manipulate them. +* Thank you! +#+begin_latex + \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_latex + + diff -r 9d8fd5ea64b2 -r c6d31837cb06 manipulating-lists/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manipulating-lists/slides.tex Wed Oct 13 11:15:37 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 9d8fd5ea64b2 -r c6d31837cb06 multiple-plots.rst --- a/multiple-plots.rst Tue Oct 12 17:15:11 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,362 +0,0 @@ -Hello friends. Welcome to this spoken tutorial on Multiple plots. - -{{{ Show the slide containing the title }}} - -{{{ Show the slide containing the outline }}} - -In this tutorial, we will learn how to draw more than one plot, how to -add legends to each plot to indicate what each plot represents. We -will also learn how to switch between the plots and create multiple -plots with different regular axes which are also called as subplots. - -.. #[Nishanth]: See diff - edited a grammatical mistake -.. #[Madhu: Done] - -{{{ Shift to terminal and start ipython -pylab }}} - -To begin with let us start ipython with pylab, by typing:: - - ipython -pylab - -on the terminal - -Let us first create set of points for our plot. For this we will use -the command called linspace:: - - x = linspace(0, 50, 10) - -linspace command creates 10 points in the interval between 0 and 50 -both inclusive. We assign these values to a variable called x. - -.. #[Nishanth]: pre requisite for this LO is basic plotting which - covers linspace and plot. So you may not need to - specify all that again. But not a problem if it is - there also. -.. #[Madhu: Since I thought the LOs are disconnected, I thought it is - better to give a very short intro to it] - -Now let us draw a plot simple sine plot using these points:: - - plot(x, sin(x)) - -This should give us a nice sine plot. - -{{{ Switch to the plot window }}} - -Oh! wait! Is that a nice sine plot? Does a sine plot actually look -like that? We know that a sine plot is a smooth curve. Is it not? What -really caused this? - -.. #[Nishanth]: See diff -.. #[Madhu: Done] - -{{{ pause for a while }}} - -A small investigation on linspace tells us that we chose too few -points in a large interval between 0 and 50 for the curve to be -smooth. This should also indicate that the plot command actually plots -the set of points given by x and sin(x) and it doesn't plot the -analytical function itself i.e. it plots the points given by -Analytical functions. So now let us use linspace again to get 500 -points between 0 and 100 and draw the sine plot - -.. #[Nishanth]: Here specify that when we do plot(x, sin(x) - it is actually plotting two sets of points - and not analytical functions. Hence the sharp - curve. -.. #[Madhu: Incorporated] - -{{{ Switch to ipython andtype }}} :: - - y = linspace(0, 50, 500) - plot(y, sin(y)) - -{{{ Change to the plot window }}} - -Now we see what we remember as a sine plot. A smooth curve. If we -carefully notice we also have two plots now one overlaid upon -another. In pylab, by default all the plots are overlaid. - -Since we have two plots now overlaid upon each other we would like to -have a way to indicate what each plot represents to distinguish -between them. This is accomplished using legends. Equivalently, the -legend command does this for us - -{{{ Switch to ipython }}}:: - - legend(['sin(x)', 'cos(x)']) - -.. #[Nishanth]: This legend may go up in the script. May be before - introducing the figure command itself. -.. #[Madhu: brought up] - -The legend command takes a single list of parameters where each -parameter is the text indicating the plots in the order of their -serial number. - -{{{ Switch to plot window }}} - -Now we can see the legends being displayed for the respective sine and -cosine plots on the plot area. - -We have learnt quite a lot of things now, so let us take up an -exercise problem. - -%% 1 %% Draw two plots overlaid upon each other, with the first plot - being a parabola of the form y = 4(x ^ 2) and the second being a - straight line of the form y = 2x + 3 in the interval -5 to 5. Use - colors to differentiate between the plots and use legends to - indicate what each plot is doing. - -{{{ pause for a while and continue from paused state }}} - -We can obtain the two plots in different colors using the following -commands:: - - x = linspace(-5, 5, 100) - plot(x, 4 * (x * x), 'b') - plot(x, (2 * x) + 3, 'g') - -Now we can use the legend command as:: - - legend(['Parabola', 'Straight Line']) - -Or we can also just give the equations of the plot:: - - legend(['y = 4(x ^ 2)', 'y = 2x + 3']) - -We now know how to draw multiple plots and use legends to indicate -which plot represents what function, but we would like to have more -control over the plots we draw. Like switch between them, perform some -operations or labelling on them individually and so on. Let us see how -to accomplish this. Before we move on, let us clear our screen. - -{{{ Switch to ipython }}}:: - - clf() - -To accomplishing more control over individual plots we use the figure -command:: - - x = linspace(0, 50, 500) - figure(1) - plot(x, sin(x), 'b') - figure(2) - plot(x, cos(x), 'g') - -{{{ Switch to plot window }}} - -Now we have two plots, a sine plot and a cosine plot in two different -figures. - -.. #[Nishanth]: figure(1) and figure(2) give two different plots. - The remaining script moves on the fact that they - give overlaid plots which is not the case. - So clear the figure and plot cos and sin without - introducing figure command. Then introduce legend - and finish off the everything on legend. - Then introduce figure command. - -.. #[Madhu: I have just moved up the text about legend command. I - think that should take care of what you suggested. If there is - some mistake with it, Punch please let me know in your next - review.] - -{{{ Have both plot window and ipython side by side }}} - -The figure command takes an integer as an argument which is the serial -number of the plot. This selects the corresponding plot. All the plot -commands we run after this are applied to the selected plot. In this -example figure 1 is the sine plot and figure 2 is the cosine plot. We -can, for example, save each plot separately - -{{{ Switch to ipython }}}:: - - savefig('/home/user/cosine.png') - figure(1) - title('sin(y)') - savefig('/home/user/sine.png') - -{{{ Have both plot window and ipython side by side }}} - -We also titled the our first plot as 'sin(y)' which we did not do for -the second plot. - -Let us attempt another exercise problem - -%% 2 %% Draw a line of the form y = x as one figure and another line - of the form y = 2x + 3. Switch back to the first figure, annotate - the x and y intercepts. Now switch to the second figure and - annotate its x and y intercepts. Save each of them. - -{{{ Pause for a while and continue from the paused state }}} - -To solve this problem we should first create the first figure using -the figure command. Before that, let us first run clf command to make -sure all the previous plots are cleared:: - - clf() - figure(1) - x = linspace(-5, 5, 100) - plot(x, x) - -Now we can use figure command to create second plotting area and plot -the figure:: - - figure(2) - plot(x, ((2 * x) + 3)) - -Now to switch between the figures we can use figure command. So let us -switch to figure 1. We are asked to annotate x and y intercepts of the -figure 1 but since figure 1 passes through origin we will have to -annotate the origin. We will annotate the intercepts for the second -figure and save them as follows:: - - figure(1) - annotate('Origin', xy=(0.0, 0.0) - figure(2) - annotate('x-intercept', xy=(0, 3)) - annotate('y-intercept', xy=(0, -1.5)) - savefig('/home/fossee/plot2.png') - figure(1) - savefig('/home/fossee/plot1.png') - -At times we run into situations where we want to compare two plots and -in such cases we want to draw both the plots in the same plotting -area. The situation is such that the two plots have different regular -axes which means we cannot draw overlaid plots. In such cases we can -draw subplots. - -We use subplot command to accomplish this - -{{{ Switch to ipython }}}:: - - subplot(2, 1, 1) - -subplot command takes three arguments, the first being the number of -rows of subplots that must be created, - -{{{ Have both plot window and ipython side by side }}} - -in this case we have 2 so it spilts the plotting area horizontally for -two subplots. The second argument specifies the number of coloumns of -subplots that must be created. We passed 1 as the argument so the -plotting area won't be split vertically and the last argument -specifies what subplot must be created now in the order of the serial -number. In this case we passed 1 as the argument, so the first subplot -that is top half is created. If we execute the subplot command as - -{{{ Switch to ipython }}}:: - - subplot(2, 1, 2) - -{{{ Switch to plot window }}} - -The lower subplot is created. Now we can draw plots in each of the -subplot area using the plot command. - -{{{ Switch to ipython }}}:: - - x = linspace(0, 50, 500) - plot(x, cos(x)) - subplot(2, 1, 1) - y = linspace(0, 5, 100) - plot(y, y ** 2) - -{{{ Have both plot window and ipython side by side }}} - -This created two plots one in each of the subplot area. The top -subplot holds a parabola and the bottom subplot holds a cosine -curve. - -As seen here we can use subplot command to switch between the subplot -as well, but we have to use the same arguments as we used to create -that subplot, otherwise the previous subplot at that place will be -automatically erased. It is clear from the two subplots that both have -different regular axes. For the cosine plot x-axis varies from 0 to -100 and y-axis varies from 0 to 1 where as for the parabolic plot the -x-axis varies from 0 to 10 and y-axis varies from 0 to 100 - -.. #[Nishanth]: stress on the similarity between subplot and figure - commands - -.. #[Madhu: I think they are not really similar. Trying to bring in - the similarity will confuse people I think.] - -%% 3 %% We know that the Pressure, Volume and Temperatures are held by -the equation PV = nRT where nR is a constant. Let us assume nR = .01 -Joules/Kelvin and T = 200K. V can be in the range from 21cc to -100cc. Draw two different plots as subplots, one being the Pressure -versus Volume plot and the other being Pressure versus Temparature -plot. - -{{{ Pause for a while and continue }}} - -To start with, we have been given the range of Volume using which we -can define the variable V:: - - V = linspace(21, 100, 500) - -Now we can create first subplot and draw Pressure versus Volume graph -using this V. We know that nRT is a constant which is equal to 2.0 -since nR = 0.01 Joules/Kelvin and T = 200 Kelvin:: - - subplot(2, 1, 1) - plot(V, 2.0/V) - -Now we can create the second subplot and draw the Pressure versus -Temparature plot as follows:: - - subplot(2, 1, 2) - plot(200, 2.0/V) - -Unfortunately we have an error now, telling x and y dimensions don't -match. This is because our V contains a set of values as returned by -linspace and hence 2.0/V which is the pressure also contains a set of -values. But the first argument to the plot command is a single -value. So to plot this data we need to create as many points as there -are in Pressure or Volume data for Temperature too, all having the -same value. This can be accomplished using:: - - T = linspace(200, 200, 500) - -We now have 500 values in T each with the value 200 Kelvin. Plotting -this data we get the required plot:: - - plot(T, 2.0/V) - -It is left as a homework to label both X and Y axes for each of the -two subplots. - -{{{ Show summary slide }}} - -.. #[Nishanth]: Exercises are missing in the script - one exercise for overlaid plot and legend - one for figure command - one for subplot must do - -This brings us to the end of another session. In this tutorial session -we learnt - - * How to draw multiple plots which are overlaid - * the figure command - * the legend command - * how to switch between the plots and perform some operations on each - of them like saving the plots and - * creating and switching between subplots - -.. #[Nishanth]: legend command can be told right after overlaid plots -.. #[Madhu: Incorporated] - -{{{ 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. -Thankyou - -.. Author : Madhu - Internal Reviewer 1 : [potential reviewer: Puneeth] - Internal Reviewer 2 : Nishanth - External Reviewer : - diff -r 9d8fd5ea64b2 -r c6d31837cb06 multiple-plots/questions.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/multiple-plots/questions.rst Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,89 @@ +Objective Questions +------------------- + +.. A mininum of 8 questions here (along with answers) + +1. Multiple plots appear in different figures by default. True or False? + + Answer: False + +#. What command is used to get individual plots separately? + + Answer: Figure + +#. Which figure is closed after the following commands are run? + +:: + + x = linspace(0, 50, 500) + figure(1) + plot(x, sin(x), 'b') + figure(2) + plot(x, cos(x), 'g') + xlabel('x') + ylabel('cos(x)') + close() + + Answer: Figure 2 + +#. Describe the plot obtained by the following commands:: + + x = linspace(0, 50, 500) + subplot(2, 1, 1) + plot(x, sin(x), 'b') + +Answer: A figure window with space for 2 plots one below the other is + obtained. The sine plot with blue line appears in the first row. + +#. Describe the plot obtained by the following commands:: + + x = linspace(0, 50, 500) + subplot(2, 1, 1) + plot(x, sin(x), 'b') + subplot(2, 1, 2) + plot(x, cos(x), 'g') + + Answer: 2 plots one below another. sine in blue on first row. cosine + in green in the second row. + +#. Describe the plot obtained by the following commands:: + + x = linspace(0, 50, 500) + subplot(2, 1, 1) + plot(x, sin(x), 'b') + subplot(2, 1, 2) + plot(x, cos(x), 'g') + subplot(2, 1, 1) + plot(x, tan(x), 'r') + + Answer: 2 plots one below another. tan in red on first row. cosine + in green in the second row. + + +#. Which of the following gives the correct legend for the commands below + + a. legend([sin, cos, tan]) + #. legend([tan, cos, sin]) + #. legend[(tan, cos, sin)] + #. legend(['sin', 'cos', 'tan']) + #. legend(['tan', 'cos', 'sin']) + +:: + + x = linspace(0, 50, 500) + figure(1) + plot(x, sin(x), 'b') + figure(2) + plot(x, cos(x), 'g') + figure(3) + plot(x, tan(x), 'b') + + Answer: legend(['tan', 'cos', 'sin']) + +Larger Questions +---------------- + +.. A minimum of 2 questions here (along with answers) + +1. Question 1 +2. Question 2 diff -r 9d8fd5ea64b2 -r c6d31837cb06 multiple-plots/script.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/multiple-plots/script.rst Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,383 @@ +.. Objectives +.. ---------- + +.. * How to draw multiple plots which are overlaid +.. * the figure command +.. * the legend command +.. * how to switch between the plots and perform some operations on each +.. of them like saving the plots and +.. * creating and switching between subplots + + +.. Prerequisites +.. ------------- + +.. 1. using the plot command interactively +.. 2. embellishing a plot +.. 3. saving plots + +.. Author : Madhu + Internal Reviewer 1 : [potential reviewer: Puneeth] + Internal Reviewer 2 : Nishanth + External Reviewer : + +Script +------ + +{{{ Show the slide containing the title }}} + +Hello friends. Welcome to this spoken tutorial on Multiple plots. + +{{{ Show the slide containing the outline }}} + +In this tutorial, we will learn how to draw more than one plot, how to +add legends to each plot to indicate what each plot represents. We +will also learn how to switch between the plots and create multiple +plots with different regular axes which are also called as subplots. + +.. #[Nishanth]: See diff - edited a grammatical mistake +.. #[Madhu: Done] + +{{{ Shift to terminal and start ipython -pylab }}} + +To begin with let us start ipython with pylab, by typing:: + + ipython -pylab + +on the terminal + +Let us first create set of points for our plot. For this we will use +the command called linspace:: + + x = linspace(0, 50, 10) + +linspace command creates 10 points in the interval between 0 and 50 +both inclusive. We assign these values to a variable called x. + +.. #[Nishanth]: pre requisite for this LO is basic plotting which + covers linspace and plot. So you may not need to + specify all that again. But not a problem if it is + there also. +.. #[Madhu: Since I thought the LOs are disconnected, I thought it is + better to give a very short intro to it] + +Now let us draw a plot simple sine plot using these points:: + + plot(x, sin(x)) + +This should give us a nice sine plot. + +{{{ Switch to the plot window }}} + +Oh! wait! Is that a nice sine plot? Does a sine plot actually look +like that? We know that a sine plot is a smooth curve. Is it not? What +really caused this? + +.. #[Nishanth]: See diff +.. #[Madhu: Done] + +{{{ pause for a while }}} + +A small investigation on linspace tells us that we chose too few +points in a large interval between 0 and 50 for the curve to be +smooth. This should also indicate that the plot command actually plots +the set of points given by x and sin(x) and it doesn't plot the +analytical function itself i.e. it plots the points given by +Analytical functions. So now let us use linspace again to get 500 +points between 0 and 100 and draw the sine plot + +.. #[Nishanth]: Here specify that when we do plot(x, sin(x) + it is actually plotting two sets of points + and not analytical functions. Hence the sharp + curve. +.. #[Madhu: Incorporated] + +{{{ Switch to ipython andtype }}} :: + + y = linspace(0, 50, 500) + plot(y, sin(y)) + +{{{ Change to the plot window }}} + +Now we see what we remember as a sine plot. A smooth curve. If we +carefully notice we also have two plots now one overlaid upon +another. In pylab, by default all the plots are overlaid. + +Since we have two plots now overlaid upon each other we would like to +have a way to indicate what each plot represents to distinguish +between them. This is accomplished using legends. Equivalently, the +legend command does this for us + +{{{ Switch to ipython }}}:: + + legend(['sin(x)', 'cos(x)']) + +.. #[Nishanth]: This legend may go up in the script. May be before + introducing the figure command itself. +.. #[Madhu: brought up] + +The legend command takes a single list of parameters where each +parameter is the text indicating the plots in the order of their +serial number. + +{{{ Switch to plot window }}} + +Now we can see the legends being displayed for the respective sine and +cosine plots on the plot area. + +We have learnt quite a lot of things now, so let us take up an +exercise problem. + +%% 1 %% Draw two plots overlaid upon each other, with the first plot + being a parabola of the form y = 4(x ^ 2) and the second being a + straight line of the form y = 2x + 3 in the interval -5 to 5. Use + colors to differentiate between the plots and use legends to + indicate what each plot is doing. + +{{{ pause for a while and continue from paused state }}} + +We can obtain the two plots in different colors using the following +commands:: + + x = linspace(-5, 5, 100) + plot(x, 4 * (x * x), 'b') + plot(x, (2 * x) + 3, 'g') + +Now we can use the legend command as:: + + legend(['Parabola', 'Straight Line']) + +Or we can also just give the equations of the plot:: + + legend(['y = 4(x ^ 2)', 'y = 2x + 3']) + +We now know how to draw multiple plots and use legends to indicate +which plot represents what function, but we would like to have more +control over the plots we draw. Like switch between them, perform some +operations or labelling on them individually and so on. Let us see how +to accomplish this. Before we move on, let us clear our screen. + +{{{ Switch to ipython }}}:: + + clf() + +To accomplishing more control over individual plots we use the figure +command:: + + x = linspace(0, 50, 500) + figure(1) + plot(x, sin(x), 'b') + figure(2) + plot(x, cos(x), 'g') + +{{{ Switch to plot window }}} + +Now we have two plots, a sine plot and a cosine plot in two different +figures. + +.. #[Nishanth]: figure(1) and figure(2) give two different plots. + The remaining script moves on the fact that they + give overlaid plots which is not the case. + So clear the figure and plot cos and sin without + introducing figure command. Then introduce legend + and finish off the everything on legend. + Then introduce figure command. + +.. #[Madhu: I have just moved up the text about legend command. I + think that should take care of what you suggested. If there is + some mistake with it, Punch please let me know in your next + review.] + +{{{ Have both plot window and ipython side by side }}} + +The figure command takes an integer as an argument which is the serial +number of the plot. This selects the corresponding plot. All the plot +commands we run after this are applied to the selected plot. In this +example figure 1 is the sine plot and figure 2 is the cosine plot. We +can, for example, save each plot separately + +{{{ Switch to ipython }}}:: + + savefig('/home/user/cosine.png') + figure(1) + title('sin(y)') + savefig('/home/user/sine.png') + +{{{ Have both plot window and ipython side by side }}} + +We also titled the our first plot as 'sin(y)' which we did not do for +the second plot. + +Let us attempt another exercise problem + +%% 2 %% Draw a line of the form y = x as one figure and another line + of the form y = 2x + 3. Switch back to the first figure, annotate + the x and y intercepts. Now switch to the second figure and + annotate its x and y intercepts. Save each of them. + +{{{ Pause for a while and continue from the paused state }}} + +To solve this problem we should first create the first figure using +the figure command. Before that, let us first run clf command to make +sure all the previous plots are cleared:: + + clf() + figure(1) + x = linspace(-5, 5, 100) + plot(x, x) + +Now we can use figure command to create second plotting area and plot +the figure:: + + figure(2) + plot(x, ((2 * x) + 3)) + +Now to switch between the figures we can use figure command. So let us +switch to figure 1. We are asked to annotate x and y intercepts of the +figure 1 but since figure 1 passes through origin we will have to +annotate the origin. We will annotate the intercepts for the second +figure and save them as follows:: + + figure(1) + annotate('Origin', xy=(0.0, 0.0) + figure(2) + annotate('x-intercept', xy=(0, 3)) + annotate('y-intercept', xy=(0, -1.5)) + savefig('/home/fossee/plot2.png') + figure(1) + savefig('/home/fossee/plot1.png') + +At times we run into situations where we want to compare two plots and +in such cases we want to draw both the plots in the same plotting +area. The situation is such that the two plots have different regular +axes which means we cannot draw overlaid plots. In such cases we can +draw subplots. + +We use subplot command to accomplish this + +{{{ Switch to ipython }}}:: + + subplot(2, 1, 1) + +subplot command takes three arguments, the first being the number of +rows of subplots that must be created, + +{{{ Have both plot window and ipython side by side }}} + +in this case we have 2 so it spilts the plotting area horizontally for +two subplots. The second argument specifies the number of coloumns of +subplots that must be created. We passed 1 as the argument so the +plotting area won't be split vertically and the last argument +specifies what subplot must be created now in the order of the serial +number. In this case we passed 1 as the argument, so the first subplot +that is top half is created. If we execute the subplot command as + +{{{ Switch to ipython }}}:: + + subplot(2, 1, 2) + +{{{ Switch to plot window }}} + +The lower subplot is created. Now we can draw plots in each of the +subplot area using the plot command. + +{{{ Switch to ipython }}}:: + + x = linspace(0, 50, 500) + plot(x, cos(x)) + subplot(2, 1, 1) + y = linspace(0, 5, 100) + plot(y, y ** 2) + +{{{ Have both plot window and ipython side by side }}} + +This created two plots one in each of the subplot area. The top +subplot holds a parabola and the bottom subplot holds a cosine +curve. + +As seen here we can use subplot command to switch between the subplot +as well, but we have to use the same arguments as we used to create +that subplot, otherwise the previous subplot at that place will be +automatically erased. It is clear from the two subplots that both have +different regular axes. For the cosine plot x-axis varies from 0 to +100 and y-axis varies from 0 to 1 where as for the parabolic plot the +x-axis varies from 0 to 10 and y-axis varies from 0 to 100 + +.. #[Nishanth]: stress on the similarity between subplot and figure + commands + +.. #[Madhu: I think they are not really similar. Trying to bring in + the similarity will confuse people I think.] + +%% 3 %% We know that the Pressure, Volume and Temperatures are held by +the equation PV = nRT where nR is a constant. Let us assume nR = .01 +Joules/Kelvin and T = 200K. V can be in the range from 21cc to +100cc. Draw two different plots as subplots, one being the Pressure +versus Volume plot and the other being Pressure versus Temparature +plot. + +{{{ Pause for a while and continue }}} + +To start with, we have been given the range of Volume using which we +can define the variable V:: + + V = linspace(21, 100, 500) + +Now we can create first subplot and draw Pressure versus Volume graph +using this V. We know that nRT is a constant which is equal to 2.0 +since nR = 0.01 Joules/Kelvin and T = 200 Kelvin:: + + subplot(2, 1, 1) + plot(V, 2.0/V) + +Now we can create the second subplot and draw the Pressure versus +Temparature plot as follows:: + + subplot(2, 1, 2) + plot(200, 2.0/V) + +Unfortunately we have an error now, telling x and y dimensions don't +match. This is because our V contains a set of values as returned by +linspace and hence 2.0/V which is the pressure also contains a set of +values. But the first argument to the plot command is a single +value. So to plot this data we need to create as many points as there +are in Pressure or Volume data for Temperature too, all having the +same value. This can be accomplished using:: + + T = linspace(200, 200, 500) + +We now have 500 values in T each with the value 200 Kelvin. Plotting +this data we get the required plot:: + + plot(T, 2.0/V) + +It is left as a homework to label both X and Y axes for each of the +two subplots. + +{{{ Show summary slide }}} + +.. #[Nishanth]: Exercises are missing in the script + one exercise for overlaid plot and legend + one for figure command + one for subplot must do + +This brings us to the end of another session. In this tutorial session +we learnt + + * How to draw multiple plots which are overlaid + * the figure command + * the legend command + * how to switch between the plots and perform some operations on each + of them like saving the plots and + * creating and switching between subplots + +.. #[Nishanth]: legend command can be told right after overlaid plots +.. #[Madhu: Incorporated] + +{{{ 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 9d8fd5ea64b2 -r c6d31837cb06 multiple-plots/slides.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/multiple-plots/slides.org Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,123 @@ +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] +#+BEAMER_FRAME_LEVEL: 1 + +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} +#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) +#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] + +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} + +#+TITLE: Accessing parts of arrays +#+AUTHOR: FOSSEE +#+EMAIL: +#+DATE: + +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc + +* Outline + - Manipulating one and multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slicing and striding on arrays to access chunks + - Read images into arrays and manipulations +* Sample Arrays + #+begin_src python + In []: A = array([12, 23, 34, 45, 56]) + + In []: 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]]) + + #+end_src +* Question 1 + Change the last column of ~C~ to zeroes. +* Solution 1 + #+begin_src python + In []: C[:, -1] = 0 + #+end_src +* Question 2 + Change ~A~ to ~[11, 12, 13, 14, 15]~. +* Solution 2 + #+begin_src python + In []: A[:] = [11, 12, 13, 14, 15] + #+end_src +* squares.png + #+begin_latex + \begin{center} + \includegraphics[scale=0.6]{squares} + \end{center} + #+end_latex +* Question 3 + - obtain ~[22, 23]~ from ~C~. + - obtain ~[11, 21, 31, 41]~ from ~C~. + - obtain ~[21, 31, 41, 0]~. +* Solution 3 + #+begin_src python + In []: C[1, 1:3] + In []: C[0:4, 0] + In []: C[1:5, 0] + #+end_src +* Question 4 + Obtain ~[[23, 24], [33, -34]]~ from ~C~ +* Solution 4 + #+begin_src python + In []: C[1:3, 2:4] + #+end_src +* Question 5 + Obtain the square in the center of the image +* Solution 5 + #+begin_src python + In []: imshow(I[75:225, 75:225]) + #+end_src +* Question 6 + Obtain the following + #+begin_src python + [[12, 0], [42, 0]] + [[12, 13, 14], [0, 0, 0]] + #+end_src + +* Solution 6 + #+begin_src python + In []: C[::3, 1::3] + In []: C[::4, 1:4] + #+end_src +* Summary + You should now be able to -- + - Manipulate 1D \& Multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slice and stride on arrays + - Read images into arrays and manipulate them. +* Thank you! +#+begin_latex + \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_latex + + diff -r 9d8fd5ea64b2 -r c6d31837cb06 multiple-plots/slides.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/multiple-plots/slides.tex Wed Oct 13 11:15:37 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 9d8fd5ea64b2 -r c6d31837cb06 using-sage/script.rst --- a/using-sage/script.rst Tue Oct 12 17:15:11 2010 +0530 +++ b/using-sage/script.rst Wed Oct 13 11:15:37 2010 +0530 @@ -1,10 +1,29 @@ -======== - Script -======== +.. Objectives +.. ---------- + +.. By the end of this tutorial you will -- + +.. 1. Get an idea of the range of things for which Sage can be used. +.. #. Know some of the functions for Calculus +.. #. Get some insight into Graphs in Sage. + + +.. Prerequisites +.. ------------- + +.. Getting Started -- Sage + +.. Author : Puneeth + Internal Reviewer : + External Reviewer : + Checklist OK? : [2010-10-05] + +Script +------ {{{ show the welcome slide }}} -Welcome to this tutorial on using Sage. +Hello Friends. Welcome to this tutorial on using Sage. {{{ show the slide with outline }}} @@ -194,4 +213,8 @@ We have looked at some of the functions available for Linear Algebra, Calculus, Graph Theory and Number theory. -Thank You! +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 9d8fd5ea64b2 -r c6d31837cb06 using-sage/slides.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/using-sage/slides.org Wed Oct 13 11:15:37 2010 +0530 @@ -0,0 +1,60 @@ +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] +#+BEAMER_FRAME_LEVEL: 1 + +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} +#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) +#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] + +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} + +#+TITLE: using Sage +#+AUTHOR: FOSSEE +#+EMAIL: +#+DATE: + +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc + +* Outline + - Calculus + - Linear Algebra + - Graph Theory + - Number Theory +* Summary + - Differentiating and Integrating + - Taylor Expansions + - Solving Equations + - Initializing Graphs & Graph families + - Prime numbers + - Factors + - Combinations & Permutations +* Thank you! +#+begin_latex + \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_latex + + diff -r 9d8fd5ea64b2 -r c6d31837cb06 using-sage/slides.tex --- a/using-sage/slides.tex Tue Oct 12 17:15:11 2010 +0530 +++ b/using-sage/slides.tex Wed Oct 13 11:15:37 2010 +0530 @@ -1,95 +1,74 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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} +% Created 2010-10-11 Mon 22:48 +\documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} -%\usepackage{times} \usepackage[T1]{fontenc} - -\usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} -\usepackage[scaled=.95]{helvet} +\usepackage{fixltx2e} +\usepackage{graphicx} +\usepackage{longtable} +\usepackage{float} +\usepackage{wrapfig} +\usepackage{soul} +\usepackage{textcomp} +\usepackage{marvosym} +\usepackage{wasysym} +\usepackage{latexsym} +\usepackage{amssymb} +\usepackage{hyperref} +\tolerance=1000 +\usepackage[english]{babel} \usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} +\usepackage{listings} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} -\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} +\title{using Sage} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + \begin{frame} - \maketitle -\end{frame} +\frametitle{Outline} +\label{sec-1} -\begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} +\begin{itemize} +\item Calculus +\item Linear Algebra +\item Graph Theory +\item Number Theory +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-2} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{itemize} +\item Differentiating and Integrating +\item Taylor Expansions +\item Solving Equations +\item Initializing Graphs \& Graph families +\item Prime numbers +\item Factors +\item Combinations \& Permutations +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-3} -\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