diff options
author | Nishanth Amuluru | 2010-10-11 22:44:21 +0530 |
---|---|---|
committer | Nishanth Amuluru | 2010-10-11 22:44:21 +0530 |
commit | 0bdc27f2da8baa5bf9b8ae34df1ae5a66e856b03 (patch) | |
tree | 23e39471c705058c10961ff465517a664abbef43 | |
parent | c777a70b51353182bcfadaaff9deb2b9d09cf9a2 (diff) | |
parent | 81a76e18a1b11c9565ee198d7ae58bd49d9b3acb (diff) | |
download | st-scripts-0bdc27f2da8baa5bf9b8ae34df1ae5a66e856b03.tar.gz st-scripts-0bdc27f2da8baa5bf9b8ae34df1ae5a66e856b03.tar.bz2 st-scripts-0bdc27f2da8baa5bf9b8ae34df1ae5a66e856b03.zip |
merged
54 files changed, 3200 insertions, 1164 deletions
diff --git a/accessing-pieces-arrays/quickref.tex b/accessing-pieces-arrays/quickref.tex index b26d168..6226b91 100644 --- a/accessing-pieces-arrays/quickref.tex +++ b/accessing-pieces-arrays/quickref.tex @@ -1,8 +1,12 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Accessing parts of arrays} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +\lstinline|C[i-1, j-1]| to access element i, j in C (mxn). +\lstinline|C[i-1]| to access i^{th} row +\lstinline|C[:, j-1]| to access j^{th} column -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +Assigning to accessed elements, changes them. + +\lstinline|A[m:n:o]| accesses the rows from \lstinline|m| +to \lstinline|n| (excluded) in steps of \lstinline|o| + +Similarly, \lstinline|C[m:n:o, p:q:r]| diff --git a/accessing-pieces-arrays/script.rst b/accessing-pieces-arrays/script.rst index 2731e0d..0ffcdfa 100644 --- a/accessing-pieces-arrays/script.rst +++ b/accessing-pieces-arrays/script.rst @@ -298,8 +298,7 @@ form of an image and confirm. Following is an exercise that you must do. -%%5%% Pause the video here, and obtain the square in the center -of the image. +%%5%% Obtain the square in the center of the image. Following is an exercise that you must do. diff --git a/accessing-pieces-arrays/slides.org b/accessing-pieces-arrays/slides.org new file mode 100644 index 0000000..5d2ce93 --- /dev/null +++ b/accessing-pieces-arrays/slides.org @@ -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 --git a/accessing-pieces-arrays/slides.tex b/accessing-pieces-arrays/slides.tex index df1462c..019260b 100644 --- a/accessing-pieces-arrays/slides.tex +++ b/accessing-pieces-arrays/slides.tex @@ -1,95 +1,203 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 18:48 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Accessing parts of arrays} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + +\begin{frame} +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Manipulating one and multi dimensional arrays +\item Access and change individual elements +\item Access and change rows and columns +\item Slicing and striding on arrays to access chunks +\item Read images into arrays and manipulations +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Sample Arrays} +\label{sec-2} + +\lstset{language=Python} +\begin{lstlisting} +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{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-3} + + Change the last column of \texttt{C} to zeroes. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 1} +\label{sec-4} + +\lstset{language=Python} +\begin{lstlisting} +In []: C[:, -1] = 0 +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-5} + + Change \texttt{A} to \texttt{[11, 12, 13, 14, 15]}. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 2} +\label{sec-6} + +\lstset{language=Python} +\begin{lstlisting} +In []: A[:] = [11, 12, 13, 14, 15] +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{squares.png} +\label{sec-7} + + \begin{center} + \includegraphics[scale=0.6]{squares} + \end{center} +\end{frame} \begin{frame} - \maketitle +\frametitle{Question 3} +\label{sec-8} + +\begin{itemize} +\item obtain \texttt{[22, 23]} from \texttt{C}. +\item obtain \texttt{[11, 21, 31, 41]} from \texttt{C}. +\item obtain \texttt{[21, 31, 41, 0]}. +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 3} +\label{sec-9} + +\lstset{language=Python} +\begin{lstlisting} +In []: C[1, 1:3] +In []: C[0:4, 0] +In []: C[1:5, 0] +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 4} +\label{sec-10} + Obtain \texttt{[[23, 24], [33, -34]]} from \texttt{C} +\end{frame} \begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 4} +\label{sec-11} + +\lstset{language=Python} +\begin{lstlisting} +In []: C[1:3, 2:4] +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 5} +\label{sec-12} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + Obtain the square in the center of the image +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 5} +\label{sec-13} +\lstset{language=Python} +\begin{lstlisting} +In []: imshow(I[75:225, 75:225]) +\end{lstlisting} +\end{frame} +\begin{frame}[fragile] +\frametitle{Question 6} +\label{sec-14} + + Obtain the following +\lstset{language=Python} +\begin{lstlisting} +[[12, 0], [42, 0]] +[[12, 13, 14], [0, 0, 0]] +\end{lstlisting} +\end{frame} \begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 6} +\label{sec-15} + +\lstset{language=Python} +\begin{lstlisting} +In []: C[::3, 1::3] +In []: C[::4, 1:4] +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-16} + + You should now be able to -- +\begin{itemize} +\item Manipulate 1D \& Multi dimensional arrays +\begin{itemize} +\item Access and change individual elements +\item Access and change rows and columns +\item Slice and stride on arrays +\end{itemize} + +\item Read images into arrays and manipulate them. +\end{itemize} +\end{frame} \begin{frame} - \frametitle{Thank you!} +\frametitle{Thank you!} +\label{sec-17} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/additional_ipython/script.rst b/additional_ipython/script.rst index 1a00973..581dbf1 100644 --- a/additional_ipython/script.rst +++ b/additional_ipython/script.rst @@ -6,6 +6,14 @@ C - D - +.. By the end of this tutorial you will be able to + +.. #. Retrieve your ipython history +.. #. View a part of the history +.. #. Save a part of your history to a file. +.. #. Run a script from within ipython + + .. Prerequisites .. ------------- @@ -81,8 +89,8 @@ The default number is 40. {{{ Pause here and try out the following exercises }}} -%% 1 %% Read through the %hist documenatation and find out how can we list all - the commands between 5 and 10 +%% 1 %% Read through the documentation of %hist and find out how to + list all the commands between 5 and 10 {{{ continue from paused state }}} @@ -128,7 +136,7 @@ arguments there after are the commands to be saved in the given order. {{{ Pause here and try out the following exercises }}} -%% 2 %% change the label on y-axis to "y" and save the lines of code +%% 2 %% Change the label on y-axis to "y" and save the lines of code accordingly {{{ continue from paused state }}} @@ -210,5 +218,5 @@ we have looked at This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India Hope you have enjoyed and found it useful. -Thankyou +Thank you! diff --git a/additional_ipython/slides.org b/additional_ipython/slides.org new file mode 100644 index 0000000..4b11b61 --- /dev/null +++ b/additional_ipython/slides.org @@ -0,0 +1,90 @@ +#+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: Additional Features of =ipython= +#+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 + + Retrieving ipython history + + Viewing a part of the history + + Saving (relevant) parts of the history to a file + + Running a script from within ipython +* Question 1 + Read through the documentation of ~%hist~ and find out how to list + all the commands between 5 and 10 +* Solution 1 + #+begin_src python + In []: %hist 5 10 + #+end_src +* Question 2 + Change the label on y-axis to "y" and save the lines of code + accordingly +* Solution 2 + #+begin_src python + In []: ylabel("y") + In []: %save /home/fossee/example_plot.py 1 3-6 10 + #+end_src +* Question 3 + Use =%hist= and =%save= and create a script that has show in it and + run it to produce and show the plot. + +* Solution 3 + #+begin_src python + In []: %hist 20 + + In []: %save /home/fossee/show_included.py 1 3-6 8 10 13 + In []: %run -i /home/fossee/show_included.py + #+end_src +* Question 4 + Run the script without using the -i option. Do you find any + difference? +* Solution 4 + We see that it raises ~NameError~ saying the name ~linspace~ is not + found. +* Summary + + Retreiving history using =%hist= command + + Vieweing only a part of history by passing an argument to %hist + + Saving the required lines of code in required order using %save + + Using %run -i command to run the saved script + +* 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 --git a/additional_ipython/slides.tex b/additional_ipython/slides.tex index df1462c..b21fa3e 100644 --- a/additional_ipython/slides.tex +++ b/additional_ipython/slides.tex @@ -1,95 +1,138 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 17:30 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Additional Features of \texttt{ipython}} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + + \begin{frame} - \maketitle +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Retrieving ipython history +\item Viewing a part of the history +\item Saving (relevant) parts of the history to a file +\item Running a script from within ipython +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} + Read through the documentation of \texttt{\%hist} and find out how to list + all the commands between 5 and 10 +\end{frame} \begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 1} +\label{sec-3} + +\lstset{language=Python} +\begin{lstlisting} +In []: %hist 5 10 +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-4} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + Change the label on y-axis to ``y'' and save the lines of code + accordingly +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 2} +\label{sec-5} + +\lstset{language=Python} +\begin{lstlisting} +In []: ylabel("y") +In []: %save /home/fossee/example_plot.py 1 3-6 10 +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Question 3} +\label{sec-6} + Use \texttt{\%hist} and \texttt{\%save} and create a script that has show in it and + run it to produce and show the plot. +\end{frame} \begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 3} +\label{sec-7} + +\lstset{language=Python} +\begin{lstlisting} +In []: %hist 20 + +In []: %save /home/fossee/show_included.py 1 3-6 8 10 13 +In []: %run -i /home/fossee/show_included.py +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 4} +\label{sec-8} + + Run the script without using the -i option. Do you find any + difference? +\end{frame} +\begin{frame} +\frametitle{Solution 4} +\label{sec-9} + We see that it raises \texttt{NameError} saying the name \texttt{linspace} is not + found. +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-10} + +\begin{itemize} +\item Retreiving history using \texttt{\%hist} command +\item Vieweing only a part of history by passing an argument to \%hist +\item Saving the required lines of code in required order using \%save +\item Using \%run -i command to run the saved script +\end{itemize} +\end{frame} \begin{frame} - \frametitle{Thank you!} +\frametitle{Thank you!} +\label{sec-11} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/advanced-features-functions/quickref.tex b/advanced-features-functions/quickref.tex index b26d168..160370e 100644 --- a/advanced-features-functions/quickref.tex +++ b/advanced-features-functions/quickref.tex @@ -1,8 +1,8 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Advanced features of functions} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +Arguments of functions can have default arguments. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +All arguments with default arguments are at the end of the definition. + +Functions can be called with keyword arguments. All the keyword +arguments should be at the end of the argument list. diff --git a/advanced-features-functions/script.rst b/advanced-features-functions/script.rst index e62d576..5b7b3e2 100644 --- a/advanced-features-functions/script.rst +++ b/advanced-features-functions/script.rst @@ -103,7 +103,7 @@ Following is an (are) exercise(s) that you must do. %%1%% Redefine the function ``welcome``, by interchanging it's arguments. Place the ``name`` argument with it's default value of -"Hello" before the ``greet`` argument. +"World" before the ``greet`` argument. Please, pause the video here. Do the exercise and then continue. @@ -142,7 +142,7 @@ Please, pause the video here. Do the exercise and then continue. welcome() - + Let us now learn what keyword arguments are. diff --git a/advanced-features-functions/slides.org b/advanced-features-functions/slides.org new file mode 100644 index 0000000..fb66b6f --- /dev/null +++ b/advanced-features-functions/slides.org @@ -0,0 +1,86 @@ +#+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: Advanced features of functions +#+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 + - Assigning default values to arguments + - Calling functions using Keyword arguments + - functions in standard library +* Question 1 + Redefine the function ~welcome~, by interchanging it's + arguments. Place the ~name~ argument with it's default value of + "World" before the ~greet~ argument. +* Solution 1 + #+begin_src python + def welcome(name="World", greet): + print greet, name + #+end_src + We get an error that reads ~SyntaxError: non-default argument + follows default argument~. When defining a function all the + argument with default values should come at the end. + +* Question 2 + See the definition of linspace using ~?~ and observe how all the + arguments with default values are towards the end. +* Solution 2 + #+begin_src python + linspace? + #+end_src +* Question 3 + Redefine the function ~welcome~ with a default value of + "Hello" to the ~greet~ argument. Then, call the function without any + arguments. +* Solution 3 + #+begin_src python + def welcome(greet="Hello", name="World"): + print greet, name + + welcome() + #+end_src +* Summary + You should now be able to -- + + define functions with default arguments + + call functions using keyword arguments +* 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 --git a/advanced-features-functions/slides.tex b/advanced-features-functions/slides.tex index df1462c..311be4f 100644 --- a/advanced-features-functions/slides.tex +++ b/advanced-features-functions/slides.tex @@ -1,95 +1,125 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-11 Mon 00:34 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Advanced features of functions} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + \begin{frame} - \maketitle +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Assigning default values to arguments +\item Calling functions using Keyword arguments +\item functions in standard library +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} + Redefine the function \texttt{welcome}, by interchanging it's + arguments. Place the \texttt{name} argument with it's default value of + ``World'' before the \texttt{greet} argument. +\end{frame} \begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 1} +\label{sec-3} + +\lstset{language=Python} +\begin{lstlisting} +def welcome(name="World", greet): + print greet, name +\end{lstlisting} + We get an error that reads \texttt{SyntaxError: non-default argument follows default argument}. When defining a function all the + argument with default values should come at the end. \end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-4} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - + See the definition of linspace using \texttt{?} and observe how all the + arguments with default values are towards the end. +\end{frame} \begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 2} +\label{sec-5} + +\lstset{language=Python} +\begin{lstlisting} +linspace? +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Question 3} +\label{sec-6} + + Redefine the function \texttt{welcome} with a default value of + ``Hello'' to the \texttt{greet} argument. Then, call the function without any + arguments. \end{frame} +\begin{frame}[fragile] +\frametitle{Solution 3} +\label{sec-7} +\lstset{language=Python} +\begin{lstlisting} +def welcome(greet="Hello", name="World"): + print greet, name + +welcome() +\end{lstlisting} +\end{frame} \begin{frame} - \frametitle{Thank you!} +\frametitle{Summary} +\label{sec-8} + + You should now be able to -- +\begin{itemize} +\item define functions with default arguments +\item call functions using keyword arguments +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-9} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/embellishing_a_plot/script.rst b/embellishing_a_plot/script.rst index b37365b..8810157 100644 --- a/embellishing_a_plot/script.rst +++ b/embellishing_a_plot/script.rst @@ -6,6 +6,15 @@ C - D - +.. By the end of this tutorial you will be able to + +.. * Modify the attributes of the plot -- color, line style, linewidth +.. * Add a title to the plot with embedded LaTeX. +.. * Label x and y axes. +.. * Add annotations to the plot. +.. * Set and Get the limits of axes. + + .. Prerequisites .. ------------- @@ -174,6 +183,10 @@ produces the required plot. .. #[Madhu: I did not understand the question] +:: + clf() + plot(x, cos(x), 'r--') + Now that we know how to produce a bare minimum plot with colour, style and thickness of our interest, we shall look at decorating the plot. @@ -184,8 +197,8 @@ Let us start with a plot of the function -x^2 + 4x - 5. {{{ Show the plot window and switch back to terminal }}} -We now have the plot in a colour and linewidth of our interest. As you can see, -the figure does not have any description describing the plot. +We now have the plot in a colour and linewidth of our interest. As you +can see, the figure does not have any description describing the plot. .. #[Madhu: Added "not". See the diff] @@ -204,10 +217,10 @@ the title accordingly. The formatting in title is messed and it does not look clean. You can imagine what would be the situation if there were fractions and more complex functions -like log and exp. Wouldn't it be good if there was LaTex like formatting? +like log and exp. Wouldn't it be good if there was LaTeX like formatting? That is also possible by adding a $ sign before and after the part of the -string that should be in LaTex style. +string that should be in LaTeX style. for instance, we can use :: @@ -217,9 +230,9 @@ for instance, we can use and we get the polynomial formatted properly. .. #[Nishanth]: Unsure if I have to give this exercise since enclosing the whole - string in LaTex style is not good + string in LaTeX style is not good -.. #[[Anoop: I guess you can go ahead with the LaTex thing, it's +.. #[[Anoop: I guess you can go ahead with the LaTeX thing, it's cool!]] .. #[Madhu: Instead of saying LaTeX style you can say Typeset math since that is how it is called as. I am not sure as well. It @@ -228,7 +241,7 @@ and we get the polynomial formatted properly. {{{ Pause here and try out the following exercises }}} %% 4 %% Change the title of the figure such that the whole title is formatted - in LaTex style + in LaTeX style {{{ continue from the paused state }}} @@ -262,11 +275,11 @@ sets the name of the y-axis as "f(x)" {{{ Pause here and try out the following exercises }}} -%% 5 %% Set the x and y labels as "x" and "f(x)" in LaTex style. +%% 5 %% Set the x and y labels as "x" and "f(x)" in LaTeX style. {{{ continue from paused state }}} -Since we need LaTex style formatting, all we have to do is enclose the string +Since we need LaTeX style formatting, all we have to do is enclose the string in between two $. Hence, :: @@ -303,6 +316,10 @@ The first is x co-ordinate and second is y co-ordinate. {{{ continue from paused state }}} +:: + + annotate("root", xy=(-4,0)) + As we can see, every annotate command makes a new annotation on the figure. Now we have everything we need to decorate a plot. but the plot would be @@ -354,7 +371,7 @@ we have looked at * Modifying the attributes of plot by passing additional arguments * How to add title - * How to incorporate LaTex style formatting + * How to incorporate LaTeX style formatting * How to label x and y axes * How to add annotations * How to set the limits of axes diff --git a/embellishing_a_plot/slides.org b/embellishing_a_plot/slides.org new file mode 100644 index 0000000..09d2cb6 --- /dev/null +++ b/embellishing_a_plot/slides.org @@ -0,0 +1,111 @@ +#+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: Embellishing a Plot +#+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 + + Modifying the color, line style & linewidth of a plot + + Adding a title to the plot (with embedded LaTeX) + + Labelling the axes + + Annotating the plot + + Setting the limits of axes. +* Question 1 + Plot sin(x) in blue colour and with linewidth as 3 +* Solution 1 + #+begin_src python + In []: clf() + In []: plot(x, sin(x), 'b', linewidth=3) + #+end_src +* Question 2 + Plot the sine curve with green filled circles. +* Solution 2 + #+begin_src python + In []: clf() + In []: plot(x, cos(x), 'go') + #+end_src +* Question 3 + Plot the curve of x vs tan(x) in red dashed line and linewidth 3 +* Solution 3 + #+begin_src python + In []: clf() + In []: plot(x, cos(x), 'r--') + #+end_src +* Question 4 + Change the title of the figure such that the whole title is + formatted in LaTex style +* Solution 4 + #+begin_src python + In []: title("$Parabolic function -x^2+4x-5$") + #+end_src +* Question 5 + Set the x and y labels as "x" and "f(x)" in LaTex style. +* Solution 5 + #+begin_src python + In []: xlabel("$x$") + In []: yalbel("$f(x)$") + #+end_src +* Question 6 + Make an annotation called "root" at the point (-4, 0). What happens + to the first annotation? +* Solution 6 + #+begin_src python + In []: annotate("root", xy=(-4,0)) + #+end_src +* Question 7 + Set the limits of axes such that the area of interest is the + rectangle (-1, -15) and (3, 0) +* Solution 7 + #+begin_src python + In []: xlim(-1, 3) + In []: ylim(-15, 0) + #+end_src +* Summary + + Modifying the attributes of plot by passing additional arguments + + How to add title + + How to incorporate LaTeX style formatting + + How to label x and y axes + + How to add annotations + + How to set the limits of axes + +* 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 --git a/embellishing_a_plot/slides.tex b/embellishing_a_plot/slides.tex index df1462c..30b69cc 100644 --- a/embellishing_a_plot/slides.tex +++ b/embellishing_a_plot/slides.tex @@ -1,95 +1,187 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 17:32 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Embellishing a Plot} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + \begin{frame} - \maketitle +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Modifying the color, line style \& linewidth of a plot +\item Adding a title to the plot (with embedded \LaTeX{}) +\item Labelling the axes +\item Annotating the plot +\item Setting the limits of axes. +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} + Plot sin(x) in blue colour and with linewidth as 3 +\end{frame} \begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 1} +\label{sec-3} + +\lstset{language=Python} +\begin{lstlisting} +In []: clf() +In []: plot(x, sin(x), 'b', linewidth=3) +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-4} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + Plot the sine curve with green filled circles. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 2} +\label{sec-5} + +\lstset{language=Python} +\begin{lstlisting} +In []: clf() +In []: plot(x, cos(x), 'go') +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Question 3} +\label{sec-6} + Plot the curve of x vs tan(x) in red dashed line and linewidth 3 +\end{frame} \begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 3} +\label{sec-7} + +\lstset{language=Python} +\begin{lstlisting} +In []: clf() +In []: plot(x, cos(x), 'r--') +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 4} +\label{sec-8} + Change the title of the figure such that the whole title is + formatted in LaTex style +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 4} +\label{sec-9} + +\lstset{language=Python} +\begin{lstlisting} +In []: title("$Parabolic function -x^2+4x-5$") +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Question 5} +\label{sec-10} + + Set the x and y labels as ``x'' and ``f(x)'' in LaTex style. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 5} +\label{sec-11} + +\lstset{language=Python} +\begin{lstlisting} +In []: xlabel("$x$") +In []: yalbel("$f(x)$") +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Question 6} +\label{sec-12} + + Make an annotation called ``root'' at the point (-4, 0). What happens + to the first annotation? +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 6} +\label{sec-13} + +\lstset{language=Python} +\begin{lstlisting} +In []: annotate("root", xy=(-4,0)) +\end{lstlisting} +\end{frame} \begin{frame} - \frametitle{Thank you!} +\frametitle{Question 7} +\label{sec-14} + + Set the limits of axes such that the area of interest is the + rectangle (-1, -15) and (3, 0) +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 7} +\label{sec-15} + +\lstset{language=Python} +\begin{lstlisting} +In []: xlim(-1, 3) +In []: ylim(-15, 0) +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-16} + +\begin{itemize} +\item Modifying the attributes of plot by passing additional arguments +\item How to add title +\item How to incorporate \LaTeX{} style formatting +\item How to label x and y axes +\item How to add annotations +\item How to set the limits of axes +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-17} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/getting-started-files/quickref.tex b/getting-started-files/quickref.tex index b26d168..17b4d33 100644 --- a/getting-started-files/quickref.tex +++ b/getting-started-files/quickref.tex @@ -1,8 +1,12 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Getting Started -- files} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +\lstinline|f = open('filename')| returns a file object. \lstinline|f| +can be used to perform further operations on the file. + +\lstinline|f.read()| reads the whole file and returns the contents. + +\lstinline|f.close()| closes the file. + +\lstinline|for line in open('filename'):| -- iterate over the file +line-by-line. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} diff --git a/getting-started-files/slides.org b/getting-started-files/slides.org new file mode 100644 index 0000000..d9e6428 --- /dev/null +++ b/getting-started-files/slides.org @@ -0,0 +1,73 @@ +#+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: Getting started with files +#+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 + - Opening and reading contents of a file + - Closing open files + - Reading all the contents of the file at once + - Reading files line by line +* Question 1 + Split the variable into a list, =pend_list=, of the lines in the + file. Hint, use the tab command to see what methods the string + variable has. +* Solution 1 + #+begin_src python + In []: pend_list = pend.splitlines() + + In []: pend_list + #+end_src +* Question 2 + Re-open the file =pendulum.txt= with =f= as the file object. +* Solution 2 + #+begin_src python + In []: f = open('/home/fossee/pendulum.txt') + #+end_src +* Summary + - Opening a file using =open= function + - Reading all the contents of the file at once using =read()= method + - Closing open files using the =close= method + - Reading files line by line by iterating using a =for= loop +* 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 --git a/getting-started-files/slides.tex b/getting-started-files/slides.tex index df1462c..f82d946 100644 --- a/getting-started-files/slides.tex +++ b/getting-started-files/slides.tex @@ -1,95 +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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 17:51 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Getting started with files} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + + \begin{frame} - \maketitle +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Opening and reading contents of a file +\item Closing open files +\item Reading all the contents of the file at once +\item Reading files line by line +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} -\begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} + Split the variable into a list, \texttt{pend\_list}, of the lines in the + file. Hint, use the tab command to see what methods the string + variable has. \end{frame} +\begin{frame}[fragile] +\frametitle{Solution 1} +\label{sec-3} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\lstset{language=Python} +\begin{lstlisting} +In []: pend_list = pend.splitlines() -\begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +In []: pend_list +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-4} + Re-open the file \texttt{pendulum.txt} with \texttt{f} as the file object. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 2} +\label{sec-5} + +\lstset{language=Python} +\begin{lstlisting} +In []: f = open('/home/fossee/pendulum.txt') +\end{lstlisting} +\end{frame} \begin{frame} - \frametitle{Thank you!} +\frametitle{Summary} +\label{sec-6} + +\begin{itemize} +\item Opening a file using \texttt{open} function +\item Reading all the contents of the file at once using \texttt{read()} method +\item Closing open files using the \texttt{close} method +\item Reading files line by line by iterating using a \texttt{for} loop +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-7} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/getting-started-ipython/quickref.tex b/getting-started-ipython/quickref.tex index b26d168..460b921 100644 --- a/getting-started-ipython/quickref.tex +++ b/getting-started-ipython/quickref.tex @@ -1,8 +1,14 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Getting started -- \texttt{ipython}} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +To start \lstinline|ipython| with \lstinline|pylab|:\\ +\lstinline| $ ipython -pylab| %$ -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +To exit: \lstinline|^D| (Ctrl-D) + +To interrupt: \lstinline|^C| (Ctrl-C) + +Tab completes partial commands + +\texttt{?} to look up documentation. + +Arrow keys to navigate the history. diff --git a/getting-started-ipython/script.rst b/getting-started-ipython/script.rst index e2f280a..c3e502f 100644 --- a/getting-started-ipython/script.rst +++ b/getting-started-ipython/script.rst @@ -105,7 +105,7 @@ possibilities. It just lists out all the possible completions. Following is an exercise that you must do. -%%1%% Type ``ab`` and hit tab to see what happens. Next, jut type +%%1%% Type ``ab`` and hit tab to see what happens. Next, just type ``a`` and hit tab to see what happens. Please, pause the video here. Do the exercise and then continue. @@ -202,9 +202,16 @@ Please, pause the video here. Do the exercises and then continue. This brings us to the end of the tutorial on getting started with ``ipython``. -In this tutorial we have learnt +In this tutorial we have learnt, how to {{{ show the outline/summary slide. }}} + 1. invoke the ``ipython`` interpreter. + #. quit the ``ipython`` interpreter. + #. navigate in the history of ``ipython``. + #. use tab-completion. + #. look-up documentation of functions. + #. interrupt incomplete or incorrect commands. + {{{ Show the "sponsored by FOSSEE" slide }}} This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India diff --git a/getting-started-ipython/slides.org b/getting-started-ipython/slides.org new file mode 100644 index 0000000..ade1aae --- /dev/null +++ b/getting-started-ipython/slides.org @@ -0,0 +1,61 @@ +#+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: Getting Started -- ~ipython~ +#+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 + + invoke the ~ipython~ interpreter + + quit the ~ipython~ interpreter + + navigate in the history of ~ipython~ + + use tab-completion + + look-up documentation of functions + + interrupt incomplete or incorrect commands +* Summary + + invoking and quitting the ~ipython~ interpreter + + navigating the history + + using tab-completion to work faster + + looking-up documentation using ~?~ + + sending keyboard interrupts using ~Ctrl-C~ + +* 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 --git a/getting-started-ipython/slides.tex b/getting-started-ipython/slides.tex index df1462c..6850029 100644 --- a/getting-started-ipython/slides.tex +++ b/getting-started-ipython/slides.tex @@ -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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 17:34 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Getting Started -- \texttt{ipython}} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} -\begin{frame} - \maketitle -\end{frame} +\maketitle + + + + + -\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!} +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item invoke the \texttt{ipython} interpreter +\item quit the \texttt{ipython} interpreter +\item navigate in the history of \texttt{ipython} +\item use tab-completion +\item look-up documentation of functions +\item interrupt incomplete or incorrect commands +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-2} + +\begin{itemize} +\item invoking and quitting the \texttt{ipython} interpreter +\item navigating the history +\item using tab-completion to work faster +\item looking-up documentation using \texttt{?} +\item sending keyboard interrupts using \texttt{Ctrl-C} +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-3} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/input_output/script.rst b/input_output/script.rst index 46eaa7d..e525872 100644 --- a/input_output/script.rst +++ b/input_output/script.rst @@ -6,6 +6,12 @@ C - D - +.. #. How to print some value +.. #. How to print using modifiers +.. #. How to take input from user +.. #. How to display a prompt to the user before taking the input + + .. Prerequisites .. ------------- @@ -73,7 +79,7 @@ As you can see, the values of x and y are substituted in place of %2.1f and %d {{{ Pause here and try out the following exercises }}} -%% 1 %% What happens when you do print "x is %d y is %f"%(x) +%% 1 %% What happens when you do ``print "x is %d y is %f" %(x, y)`` {{{ continue from paused state }}} @@ -172,6 +178,9 @@ prints the string given as argument and then waits for the user input. {{{ continue from paused state }}} +.. #[Puneeth: We didn't talk of new-line character till now, did we?] +.. #[Puneeth: non-programmers might not know?] + The trick is to include a newline character at the end of the prompt string. :: diff --git a/input_output/slides.org b/input_output/slides.org new file mode 100644 index 0000000..df7e36f --- /dev/null +++ b/input_output/slides.org @@ -0,0 +1,84 @@ +#+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: I/O +#+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 + - Showing output to the user. + - Taking input from the user. +* Question 1 + What happens when you do ~print "x is %d y is %f" %(x, y)~ +* Solution 1 + ~int~ value of ~x~ and ~float~ value of ~y~ are printed corresponding to the + modifiers used in the ~print~ statement +* Question 2 + Enter the number 5.6 as input and store it in a variable called + ~c~. +* Solution 2 + #+begin_src python + In []: c = raw_input() + 5.6 + In []: c + #+end_src +* Question 3 + What happens when you do not enter anything and hit enter +* Solution 3 + #+begin_src python + In []: c = raw_input() + <RET> + In []: c + #+end_src +* Question 4 + How do you display a prompt and let the user enter input in a new line +* Solution 4 + #+begin_src python + In []: ip = raw_input("Please enter a number in the next line\n> ") + #+end_src +* Summary + You should now be able to -- + + Print a value "as is" + + Print a value using using modifiers + + Accept input from user + + Display a prompt before accepting input +* 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 --git a/input_output/slides.tex b/input_output/slides.tex index df1462c..79ce52b 100644 --- a/input_output/slides.tex +++ b/input_output/slides.tex @@ -1,95 +1,133 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 21:00 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{I/O} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + \begin{frame} - \maketitle +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Showing output to the user. +\item Taking input from the user. +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} -\begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} + What happens when you do \texttt{print "x is \%d y is \%f" \%(x, y)} \end{frame} +\begin{frame} +\frametitle{Solution 1} +\label{sec-3} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \texttt{int} value of \texttt{x} and \texttt{float} value of \texttt{y} are printed corresponding to the + modifiers used in the \texttt{print} statement +\end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-4} + + Enter the number 5.6 as input and store it in a variable called + \texttt{c}. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 2} +\label{sec-5} + +\lstset{language=Python} +\begin{lstlisting} +In []: c = raw_input() +5.6 +In []: c +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Question 3} +\label{sec-6} + What happens when you do not enter anything and hit enter +\end{frame} \begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 3} +\label{sec-7} + +\lstset{language=Python} +\begin{lstlisting} +In []: c = raw_input() +<RET> +In []: c +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 4} +\label{sec-8} + + How do you display a prompt and let the user enter input in a new line +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 4} +\label{sec-9} +\lstset{language=Python} +\begin{lstlisting} +In []: ip = raw_input("Please enter a number in the next line\n> ") +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-10} + + You should now be able to -- +\begin{itemize} +\item Print a value ``as is'' +\item Print a value using using modifiers +\item Accept input from user +\item Display a prompt before accepting input +\end{itemize} +\end{frame} \begin{frame} - \frametitle{Thank you!} +\frametitle{Thank you!} +\label{sec-11} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/loading-data-from-files/quickref.tex b/loading-data-from-files/quickref.tex index b26d168..c3bbe95 100644 --- a/loading-data-from-files/quickref.tex +++ b/loading-data-from-files/quickref.tex @@ -1,8 +1,12 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Loading data from files} + +\lstinline|loadtxt('filename')| returns the columns of file in one +sequence. + +\lstinline|x, y = loadtxt('filename', unpack=True)| to obtain a file +with 2 columns in separate sequences. + +\lstinline|loadtxt('filename', delimiter=';')|, if the file has +columns separated by ';' instead of spaces/tabs. -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} diff --git a/loading-data-from-files/slides.org b/loading-data-from-files/slides.org new file mode 100644 index 0000000..91c188a --- /dev/null +++ b/loading-data-from-files/slides.org @@ -0,0 +1,67 @@ +#+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: Loading data from files +#+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 + + Read data from files with a single column of data + + Read data from files with multiple columns +* Question 1 + Read the file ~pendulum_semicolon.txt~ which contains the same data + as ~pendulum.txt~, but the columns are separated by semi-colons + instead of spaces. Use the IPython help to see how to do this. +* Solution 1 + #+begin_src python + In []: L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';') + + In []: print L + + In []: print T + #+end_src +* Summary + + Read data from files, containing a single column of data using the + ~loadtxt~ command. + + Read multiple columns of data, separated by spaces or other + delimiters. +* Thank you! +#+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 --git a/loading-data-from-files/slides.tex b/loading-data-from-files/slides.tex index df1462c..858d769 100644 --- a/loading-data-from-files/slides.tex +++ b/loading-data-from-files/slides.tex @@ -1,95 +1,90 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 18:12 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Loading data from files} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + \begin{frame} - \maketitle +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Read data from files with a single column of data +\item Read data from files with multiple columns +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} -\begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} + Read the file \texttt{pendulum\_semicolon.txt} which contains the same data + as \texttt{pendulum.txt}, but the columns are separated by semi-colons + instead of spaces. Use the IPython help to see how to do this. \end{frame} +\begin{frame}[fragile] +\frametitle{Solution 1} +\label{sec-3} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\lstset{language=Python} +\begin{lstlisting} +In []: L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';') -\begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} -\end{frame} +In []: print L +In []: print T +\end{lstlisting} +\end{frame} \begin{frame} - \frametitle{Thank you!} +\frametitle{Summary} +\label{sec-4} + +\begin{itemize} +\item Read data from files, containing a single column of data using the + \texttt{loadtxt} command. +\item Read multiple columns of data, separated by spaces or other + delimiters. +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-5} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/loops/quickref.tex b/loops/quickref.tex index b26d168..e0b8d61 100644 --- a/loops/quickref.tex +++ b/loops/quickref.tex @@ -1,8 +1,16 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{loops} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +To iterate over a sequence: \lstinline|for i in sequence:|\\ +\texttt{i} is the looping variable. + +To iterate while a condition is true: \lstinline|while condition:| + +Blocks in python are indented. To end block return to the previous +indentation. + +To break out of the innermost loop: \lstinline|break| + +To skip to end of current iteration: \lstinline|continue| + +\lstinline|pass| is just a syntactic filler. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} diff --git a/loops/script.rst b/loops/script.rst index 0c1c886..ead076d 100644 --- a/loops/script.rst +++ b/loops/script.rst @@ -63,7 +63,7 @@ to the right by 4 spaces. Following is an exercise that you must do. %%1%% Write a ``while`` loop to print the squares of all the even -numbers below 10. Then, return to the video. +numbers below 10. Please, pause the video here. Do the exercise and then continue. @@ -88,8 +88,8 @@ then iterate over it and print the required stuff. Following is an exercise that you must do. -%%2%% Pause the video here and write a ``for`` loop to print the -squares of all the even numbers below 10. Then, return to the video. +%%2%% Write a ``for`` loop to print the squares of all the even +numbers below 10. Please, pause the video here. Do the exercise and then continue. diff --git a/loops/slides.org b/loops/slides.org new file mode 100644 index 0000000..2003620 --- /dev/null +++ b/loops/slides.org @@ -0,0 +1,87 @@ +#+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: Loops +#+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 + - Loop while a condition is true. + - Iterate over a sequence + - Breaking out of loops. + - Skipping iterations. +* Question 1 + Write a ~while~ loop to print the squares of all the even + numbers below 10. +* Solution 1 + #+begin_src python + In []: i = 2 + + In []: while i<10: + ....: print i*i + ....: i += 2 + #+end_src +* Question 2 + Write a ~for~ loop to print the squares of all the even numbers + below 10. +* Solution 2 + #+begin_src python + In []: for n in range(2, 10, 2): + ....: print n*n + #+end_src +* Question 3 + Using the ~continue~ keyword modify the ~for~ loop to print the + squares of even numbers below 10, to print the squares of only + multiples of 4. (Do not modify the range function call.) +* Solution 3 + #+begin_src python + for n in range(2, 10, 2): + if n%4: + continue + print n*n + #+end_src +* Summary + You should now be able to -- + - use the ~for~ loop + - use the ~while~ loop + - Use ~break~, ~continue~ and ~pass~ statements +* 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 --git a/loops/slides.tex b/loops/slides.tex index df1462c..245bb7e 100644 --- a/loops/slides.tex +++ b/loops/slides.tex @@ -1,95 +1,128 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 21:15 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Loops} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + \begin{frame} - \maketitle +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Loop while a condition is true. +\item Iterate over a sequence +\item Breaking out of loops. +\item Skipping iterations. +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} -\begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} + Write a \texttt{while} loop to print the squares of all the even + numbers below 10. \end{frame} +\begin{frame}[fragile] +\frametitle{Solution 1} +\label{sec-3} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\lstset{language=Python} +\begin{lstlisting} +In []: i = 2 +In []: while i<10: + ....: print i*i + ....: i += 2 +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-4} + + Write a \texttt{for} loop to print the squares of all the even numbers + below 10. +\end{frame} \begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 2} +\label{sec-5} + +\lstset{language=Python} +\begin{lstlisting} +In []: for n in range(2, 10, 2): + ....: print n*n +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 3} +\label{sec-6} + Using the \texttt{continue} keyword modify the \texttt{for} loop to print the + squares of even numbers below 10, to print the squares of only + multiples of 4. (Do not modify the range function call.) +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 3} +\label{sec-7} + +\lstset{language=Python} +\begin{lstlisting} +for n in range(2, 10, 2): + if n%4: + continue + print n*n +\end{lstlisting} +\end{frame} \begin{frame} - \frametitle{Thank you!} +\frametitle{Summary} +\label{sec-8} + + You should now be able to -- +\begin{itemize} +\item use the \texttt{for} loop +\item use the \texttt{while} loop +\item Use \texttt{break}, \texttt{continue} and \texttt{pass} statements +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-9} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/lstsq/script.rst b/lstsq/script.rst index a6b5575..59f1809 100644 --- a/lstsq/script.rst +++ b/lstsq/script.rst @@ -6,11 +6,13 @@ C - D - +.. Plotting a least square fit line + .. Prerequisites .. ------------- .. 1. Basic Plotting - 2. Arrays +.. 2. Arrays .. Author : Nishanth Amuluru Internal Reviewer : diff --git a/lstsq/slides.org b/lstsq/slides.org new file mode 100644 index 0000000..d32f5c6 --- /dev/null +++ b/lstsq/slides.org @@ -0,0 +1,52 @@ +#+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: Least square fit +#+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 + - Plotting a Least square fit line +* Summary + You should now be able to -- + - Plot a least square fit line. +* 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 --git a/lstsq/slides.tex b/lstsq/slides.tex index df1462c..5f07014 100644 --- a/lstsq/slides.tex +++ b/lstsq/slides.tex @@ -1,95 +1,66 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 19:02 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Least square fit} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} -\begin{frame} - \maketitle -\end{frame} +\maketitle + + -\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} + + + + +\begin{frame} +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Plotting a Least square fit line +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-2} + You should now be able to -- +\begin{itemize} +\item Plot a least square fit line. +\end{itemize} +\end{frame} \begin{frame} - \frametitle{Thank you!} +\frametitle{Thank you!} +\label{sec-3} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/manipulating-strings/quickref.tex b/manipulating-strings/quickref.tex index b26d168..533a1ef 100644 --- a/manipulating-strings/quickref.tex +++ b/manipulating-strings/quickref.tex @@ -1,8 +1,14 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +\textbf{Manipulating strings} -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +String indexing starts from 0, like lists. -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +\lstinline|s = `Hello World'|\\ +\lstinline|s[0:5]| gives \texttt{Hello}\\ +\lstinline|s[6:]| gives \textt{World}\\ +\lstinline|s[6::2]| gives \textt{Wrd}\\ + +\lstinline|s.replace('e', 'a')| returns a new string with all e's +replaced by a. + +\lstinline|s.lower()| and \lstinline|s.upper()| return new strings +with all lower and upper case letters, respectively. diff --git a/manipulating-strings/script.rst b/manipulating-strings/script.rst index 1ba16d1..7873575 100644 --- a/manipulating-strings/script.rst +++ b/manipulating-strings/script.rst @@ -6,7 +6,7 @@ .. 1. Slice strings and get sub-strings out of them .. #. Reverse strings .. #. Replace characters in strings. -.. #. Convert to strings to upper or lower case +.. #. Convert strings to upper or lower case .. #. joining a list of strings .. Prerequisites @@ -84,7 +84,7 @@ using ``s[-1]``. Following is an exercise that you must do. %%1%% Obtain the sub-string excluding the first and last characters -from the string. +from the string s. Please, pause the video here. Do the exercise(s) and then continue. @@ -167,6 +167,8 @@ Please, pause the video here. Do the exercise and then continue. :: + s in week + s.lower()[:3] in week We just convert any input string to lower case and then check if it is @@ -191,7 +193,7 @@ method of strings. Following is an exercise that you must do. -%%3%% Replace the ``[dot]`` with ``.`` +%%3%% Replace the ``[dot]`` with ``.`` in ``email`` Please, pause the video here. Do the exercise and then continue. diff --git a/manipulating-strings/slides.org b/manipulating-strings/slides.org new file mode 100644 index 0000000..cb8adfd --- /dev/null +++ b/manipulating-strings/slides.org @@ -0,0 +1,94 @@ +#+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: Manipulating strings +#+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 + - Slicing strings to get sub-strings + - Reversing strings + - Replacing characters in strings. + - Converting strings to upper or lower case + - Joining a list of strings +* Question 1 + Obtain the sub-string excluding the first and last characters from + the string ~s~. +* Solution 1 + #+begin_src python + In []: s[1:-1] + #+end_src +* Question 2 + Given a list week, week = ~week = ["sun", "mon", "tue", "wed", + "thu", "fri", "sat"]~. Check if ~s~ is a valid name of a day of the + week. Change the solution to this problem, to include forms like, + SAT, SATURDAY, Saturday and Sat. +* Solution 2 + #+begin_src python + In []: s in week + In []: s.lower()[:3] in week + #+end_src +* Question 3 + Given ~email~ -- ~info@fossee[dot]in~ + + Replace the ~[dot]~ with ~.~ in ~email~ +* Solution 3 + #+begin_src python + email.replace('[dot], '.') + print email + #+end_src +* Question 4 + From the ~email_str~ that we generated, change the separator to be a + semicolon instead of a comma. +* Solution 4 + #+begin_src python + email_str = email_str.replace(",", ";") + #+end_src +* Summary + You should now be able to -- + - Slice strings and get sub-strings out of them + - Reverse strings + - Replace characters in strings. + - Convert strings to upper or lower case + - Join a list of strings + +* 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 --git a/manipulating-strings/slides.tex b/manipulating-strings/slides.tex index df1462c..02e2b7e 100644 --- a/manipulating-strings/slides.tex +++ b/manipulating-strings/slides.tex @@ -1,95 +1,142 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-11 Mon 11:27 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Manipulating strings} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + \begin{frame} - \maketitle +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Slicing strings to get sub-strings +\item Reversing strings +\item Replacing characters in strings. +\item Converting strings to upper or lower case +\item Joining a list of strings +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} + Obtain the sub-string excluding the first and last characters from + the string \texttt{s}. +\end{frame} \begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 1} +\label{sec-3} + +\lstset{language=Python} +\begin{lstlisting} +In []: s[1:-1] +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-4} + + Given a list week, week = \texttt{week = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]}. Check if \texttt{s} is a valid name of a day of the + week. Change the solution to this problem, to include forms like, + SAT, SATURDAY, Saturday and Sat. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 2} +\label{sec-5} + +\lstset{language=Python} +\begin{lstlisting} +In []: s in week +In []: s.lower()[:3] in week +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Question 3} +\label{sec-6} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + Given \texttt{email} -- \texttt{info@fossee[dot]in} + Replace the \texttt{[dot]} with \texttt{.} in \texttt{email} +\end{frame} \begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 3} +\label{sec-7} + +\lstset{language=Python} +\begin{lstlisting} +email.replace('[dot], '.') +print email +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 4} +\label{sec-8} + From the \texttt{email\_str} that we generated, change the separator to be a + semicolon instead of a comma. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 4} +\label{sec-9} + +\lstset{language=Python} +\begin{lstlisting} +email_str = email_str.replace(",", ";") +\end{lstlisting} +\end{frame} \begin{frame} - \frametitle{Thank you!} +\frametitle{Summary} +\label{sec-10} + + You should now be able to -- +\begin{itemize} +\item Slice strings and get sub-strings out of them +\item Reverse strings +\item Replace characters in strings. +\item Convert strings to upper or lower case +\item Join a list of strings +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-11} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/matrices/script.rst b/matrices/script.rst index fa30811..4bc3a3f 100644 --- a/matrices/script.rst +++ b/matrices/script.rst @@ -70,6 +70,8 @@ Similarly, it does matrix subtraction, that is element by element subtraction. Now let us try, + +{{{ Switch to next slide, Matrix multiplication }}} :: m3 * m2 @@ -120,9 +122,9 @@ To find out the transpose of a matrix we can do, Matrix name dot capital T will give the transpose of a matrix -{{{ switch to next slide, Euclidean norm of inverse of matrix }}} +{{{ switch to next slide, Frobenius norm of inverse of matrix }}} -Now let us try to find out the Euclidean norm of inverse of a 4 by 4 +Now let us try to find out the Frobenius norm of inverse of a 4 by 4 matrix, the matrix being, :: @@ -131,17 +133,17 @@ matrix, the matrix being, The inverse of a matrix A, A raise to minus one is also called the reciprocal matrix such that A multiplied by A inverse will give 1. The -Euclidean norm or the Frobenius norm of a matrix is defined as square -root of sum of squares of elements in the matrix. Pause here and try -to solve the problem yourself, the inverse of a matrix can be found -using the function ``inv(A)``. +Frobenius norm of a matrix is defined as square root of sum of squares +of elements in the matrix. Pause here and try to solve the problem +yourself, the inverse of a matrix can be found using the function +``inv(A)``. And here is the solution, first let us find the inverse of matrix m5. :: im5 = inv(m5) -And the euclidean norm of the matrix ``im5`` can be found out as, +And the Frobenius norm of the matrix ``im5`` can be found out as, :: sum = 0 @@ -166,16 +168,18 @@ The solution for the problem is, {{{ switch to slide the ``norm()`` method }}} -Well! to find the Euclidean norm and Infinity norm we have an even easier +Well! to find the Frobenius norm and Infinity norm we have an even easier method, and let us see that now. The norm of a matrix can be found out using the method -``norm()``. Inorder to find out the Euclidean norm of the matrix im5, +``norm()``. Inorder to find out the Frobenius norm of the matrix im5, we do, :: norm(im5) +Euclidean norm is also called Frobenius norm. + And to find out the Infinity norm of the matrix im5, we do, :: diff --git a/other-type-of-plots/bar-chart-hatch.png b/other-type-of-plots/bar-chart-hatch.png Binary files differnew file mode 100644 index 0000000..7b48125 --- /dev/null +++ b/other-type-of-plots/bar-chart-hatch.png diff --git a/other-type-of-plots/company-a-data.txt b/other-type-of-plots/company-a-data.txt new file mode 100644 index 0000000..06f4ca4 --- /dev/null +++ b/other-type-of-plots/company-a-data.txt @@ -0,0 +1,2 @@ +2.000000000000000000e+03 2.001000000000000000e+03 2.002000000000000000e+03 2.003000000000000000e+03 2.004000000000000000e+03 2.005000000000000000e+03 2.006000000000000000e+03 2.007000000000000000e+03 2.008000000000000000e+03 2.009000000000000000e+03 2.010000000000000000e+03 +2.300000000000000000e+01 5.500000000000000000e+01 3.200000000000000000e+01 6.500000000000000000e+01 8.800000000000000000e+01 5.000000000000000000e+00 1.400000000000000000e+01 6.700000000000000000e+01 2.300000000000000000e+01 2.300000000000000000e+01 1.200000000000000000e+01 diff --git a/other-type-of-plots/script.rst b/other-type-of-plots/script.rst index 010045b..aa5e25b 100644 --- a/other-type-of-plots/script.rst +++ b/other-type-of-plots/script.rst @@ -20,7 +20,6 @@ In this tutorial we will cover scatter plot, pie chart, bar chart and log plot. We will also see few other plots and also introduce you to the matplotlib help. - Let us start with scatter plot. {{{ switch to the next slide }}} @@ -55,11 +54,12 @@ profit percentages. {{{ close the file and switch to the terminal }}} -To product the scatter plot first we need to load the data from the +To produce the scatter plot first we need to load the data from the file using ``loadtxt``. We learned in one of the previous sessions, and it can be done as :: - year,profit = loadtxt('/home/fossee/other-plot/company-a-data.txt',dtype=type(int())) + year,profit = + loadtxt('/home/fossee/other-plot/company-a-data.txt',dtype=type(int())) Now in-order to generate the scatter graph we will use the function ``scatter()`` @@ -100,9 +100,9 @@ We can plot the pie chart using the function ``pie()``. pie(profit,labels=year) -Notice that we passed two arguments to the function ``pie()``. The -first one the values and the next one the set of labels to be used in -the pie chart. +Notice that we passed two arguments to the function ``pie()``. First +one the values and the next one the set of labels to be used in the +pie chart. {{{ switch to the next slide which has the problem statement of problem to be tried out }}} @@ -195,14 +195,10 @@ matplotlib over the internet. Help about matplotlib can be obtained from matplotlib.sourceforge.net/contents.html -.. #[[Anoop: I am not so sure how to do the rest of it, so I guess we - can just browse through the side and tell them few. What is your - opinion??]] - -Now let us see few plots from -matplotlib.sourceforge.net/users/screenshots.html -{{{ browse through the site quickly }}} +More plots can be seen at +matplotlib.sourceforge.net/users/screenshots.html and also at +matplotlib.sourceforge.net/gallery.html {{{ switch to recap slide }}} diff --git a/parsing_data/slides.org b/parsing_data/slides.org new file mode 100644 index 0000000..0027e86 --- /dev/null +++ b/parsing_data/slides.org @@ -0,0 +1,84 @@ +#+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: Parsing Data +#+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 + - What is meant by parsing data? + - String operations required for parsing + - Converting between data-types. +* Question 1 + Split the variable line using a space as argument. Is it same as + splitting without an argument ? +* Solution 1 + We see that when we split on space, multiple whitespaces are not + clubbed as one and there is an empty string everytime there are two + consecutive spaces. +* Question 2 + What happens to the white space inside the sentence when it is + stripped? +* Solution 2 + #+begin_src python + In []: a_str = " white space " + In []: a_str.strip() + #+end_src +* Question 3 + What happens if you do =int("1.25")= +* Solution 3 + It raises an error since converting a float string into integer + directly is not possible. It involves an intermediate step of + converting to float. + #+begin_src python + In []: dcml_str = "1.25" + In []: flt = float(dcml_str) + In []: flt + In []: number = int(flt) + In []: number + #+end_src +* Summary + + How to tokenize a string using various delimiters + + How to get rid of extra white space around + + How to convert from one type to another + + How to parse input data and perform computations on it +* 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 --git a/parsing_data/slides.tex b/parsing_data/slides.tex index df1462c..cca51a0 100644 --- a/parsing_data/slides.tex +++ b/parsing_data/slides.tex @@ -1,95 +1,124 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 18:28 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Parsing Data} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + \begin{frame} - \maketitle +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item What is meant by parsing data? +\item String operations required for parsing +\item Converting between data-types. +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} -\begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} + Split the variable line using a space as argument. Is it same as + splitting without an argument ? \end{frame} +\begin{frame} +\frametitle{Solution 1} +\label{sec-3} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + We see that when we split on space, multiple whitespaces are not + clubbed as one and there is an empty string everytime there are two + consecutive spaces. +\end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-4} + What happens to the white space inside the sentence when it is + stripped? +\end{frame} \begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 2} +\label{sec-5} + +\lstset{language=Python} +\begin{lstlisting} +In []: a_str = " white space " +In []: a_str.strip() +\end{lstlisting} \end{frame} +\begin{frame} +\frametitle{Question 3} +\label{sec-6} + What happens if you do \texttt{int("1.25")} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 3} +\label{sec-7} + + It raises an error since converting a float string into integer + directly is not possible. It involves an intermediate step of + converting to float. +\lstset{language=Python} +\begin{lstlisting} +In []: dcml_str = "1.25" +In []: flt = float(dcml_str) +In []: flt +In []: number = int(flt) +In []: number +\end{lstlisting} +\end{frame} \begin{frame} - \frametitle{Thank you!} +\frametitle{Summary} +\label{sec-8} + +\begin{itemize} +\item How to tokenize a string using various delimiters +\item How to get rid of extra white space around +\item How to convert from one type to another +\item How to parse input data and perform computations on it +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-9} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/savefig/script.rst b/savefig/script.rst index 506428e..87080d0 100644 --- a/savefig/script.rst +++ b/savefig/script.rst @@ -9,8 +9,16 @@ Savefig ======= -Hello and welcome to the tutorial. In this tutorial you will learn how -to save plots using Python. +{{{ Show the first slide }}} + +Hello and welcome to the tutorial saving plots. + +{{{ switch to next slide, outline slide }}} + +In this tutorial you will learn how to save plots using Python. And +saving in different formats, and locating the file in the file system. + +{{{ switch to next slide, a sine wave}}} Start your IPython interpreter with the command :: @@ -38,9 +46,11 @@ Done! we have made a very basic sine plot, now let us see how to save the plot for future use so that you can embed the plot in your reports. +{{{ switch to next slide, savefig() }}} + {{{ Switch the focus to IPython interpreter window }}} -For saving the plot, we will use savefig function, and it has to be +For saving the plot, we will use ``savefig()`` function, and it has to be done with the plot window open. The statement is, :: savefig('/home/fossee/sine.png') @@ -73,6 +83,8 @@ Yes, the file ``sine.png`` is here and let us check it. close it and return to IPython interpreter, make sure the plot window is still open, also don't close the file browser window }}} +{{{ switch to next slide, More on savefig() }}} + So in-order to save a plot, we use ``savefig`` function. ``savefig`` can save the plot in many formats, such as pdf - portable document format, ps - post script, eps - encapsulated post script, svg - @@ -81,15 +93,19 @@ support transparency etc. .. #[[slide must give the extensions for the files - Anoop]] +{{{ switch to next slide, exercise 1 }}} + Let us now try to save the plot in eps format. ``eps`` stands for encapsulated post script, and it can be embedded in your latex -documents. +documents. Pause here and try to figure it out yourself. {{{ Switch focus to the already open plot window }}} We still have the sine plot with us, and now let us save the plot as ``sine.eps``. +{{{ switch to next slide, solution 1 }}} + {{{ Switch focus to IPython interpreter }}} Now, We will save the plot using the function ``savefig`` :: @@ -105,10 +121,17 @@ seconds and then double click and open the file }}} Yes! the new file ``sine.eps`` is here. +{{{ switch to next slide, exercise 2 }}} + Now you may try saving the same in pdf, ps, svg formats. -Let us review what we have learned in this session! We have learned to -save plots in different formats using the function ``savefig()``. +{{{ Switch to summary slide }}} + +This brings us to the end of this tutorial, in this tutorial we +learned to save plots using the function ``savefig()``. Saving the +plots in different formats and locating the files in the file system. + +{{{ switch to Thank you slide }}} Thank you! diff --git a/savefig/slides.org b/savefig/slides.org new file mode 100644 index 0000000..4278516 --- /dev/null +++ b/savefig/slides.org @@ -0,0 +1,99 @@ +#+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: Savefig +#+AUTHOR: FOSSEE +#+EMAIL: info@fossee.in +#+DATE: 2010-10-11 Mon + +#+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 + - Saving plots. + - Plotting in different formats. + - Locating the file in the file system. + +* Creating a basic plot + Plot a sine wave from -3pi to 3pi. + #+begin_src python + In []: x = linspace(-3*pi,3*pi,100) + + In []: plot(x, sin(x)) + #+end_src +* savefig() +** savefig() - to save plots + : syntax: savefig(fname) +** example +*** savefig('/home/fossee/sine.png') + - file sine.png saved to the folder /home/fossee + - .png - file type + +* More on savefig() +** Recall + - .png - file type +** File types supported +*** .pdf - PDF(Portable Document Format) +*** .ps - PS(Post Script) +*** .eps - Encapsulated Post Script + ~to be used with~ LaTeX ~documents~ +*** .svg - Scalable Vector Graphics + ~vector graphics~ +*** .png - Portable Network Graphics + ~supports transparency~ +* Exercise 1 + Save the sine plot in the format EPS which can be embedded in LaTeX documents. +* Solution 1 + #+begin_src python + savefig('/home/fossee/sine.eps') + #+end_src +* Exercise 2 + Save the sine plot in PDF, PS and SVG formats. + +* Summary + You should now be able to + - Use ~savefig()~ function + - Save plots in different formats + - PDF + - PS + - PNG + - SVG + - EPS + - Locating the files in file system. + +* 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 --git a/savefig/slides.tex b/savefig/slides.tex new file mode 100644 index 0000000..06d530b --- /dev/null +++ b/savefig/slides.tex @@ -0,0 +1,185 @@ +% Created 2010-10-11 Mon 17:08 +\documentclass[presentation]{beamer} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{fixltx2e} +\usepackage{graphicx} +\usepackage{longtable} +\usepackage{float} +\usepackage{wrapfig} +\usepackage{soul} +\usepackage{t1enc} +\usepackage{textcomp} +\usepackage{marvosym} +\usepackage{wasysym} +\usepackage{latexsym} +\usepackage{amssymb} +\usepackage{hyperref} +\tolerance=1000 +\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}} + +\title{Savefig} +\author{FOSSEE} +\date{2010-10-11 Mon} + +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} +\begin{document} + +\maketitle + + + + + + + + + +\begin{frame} +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Saving plots. +\item Plotting in different formats. +\item Locating the file in the file system. +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Creating a basic plot} +\label{sec-2} + + Plot a sine wave from -3pi to 3pi. +\begin{verbatim} +In []: x = linspace(-3*pi,3*pi,100) + +In []: plot(x, sin(x)) +\end{verbatim} +\end{frame} +\begin{frame}[fragile] +\frametitle{savefig()} +\label{sec-3} +\begin{itemize} + +\item savefig() - to save plots +\label{sec-3_1}% +\begin{verbatim} + syntax: savefig(fname) +\end{verbatim} + + +\item example +\label{sec-3_2}% +\begin{itemize} + +\item savefig('/home/fossee/sine.png') +\label{sec-3_2_1}% +\begin{itemize} +\item file sine.png saved to the folder /home/fossee +\item .png - file type +\end{itemize} + + +\end{itemize} % ends low level +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{More on savefig()} +\label{sec-4} +\begin{itemize} + +\item Recall +\label{sec-4_1}% +\begin{itemize} +\item .png - file type +\end{itemize} + + +\item File types supported +\label{sec-4_2}% +\begin{itemize} + +\item .pdf - PDF(Portable Document Format)\\ +\label{sec-4_2_1}% +\item .ps - PS(Post Script)\\ +\label{sec-4_2_2}% +\item .eps - Encapsulated Post Script\\ +\label{sec-4_2_3}% +\texttt{to be used with} \LaTeX{} \texttt{documents} + +\item .svg - Scalable Vector Graphics\\ +\label{sec-4_2_4}% +\texttt{vector graphics} + +\item .png - Portable Network Graphics\\ +\label{sec-4_2_5}% +\texttt{supports transparency} +\end{itemize} % ends low level +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{Exercise 1} +\label{sec-5} + + Save the sine plot in the format EPS which can be embedded in \LaTeX{} documents. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 1} +\label{sec-6} + +\begin{verbatim} +savefig('/home/fossee/sine.eps') +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Exercise 2} +\label{sec-7} + + Save the sine plot in PDF, PS and SVG formats. +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-8} + + You should now be able to +\begin{itemize} +\item Use \texttt{savefig()} function +\item Save plots in different formats + +\begin{itemize} +\item PDF +\item PS +\item PNG +\item SVG +\item EPS +\end{itemize} + +\item Locating the files in file system. +\end{itemize} + + +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-9} + + \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 --git a/sets/script.rst b/sets/script.rst index 944097f..ffc2084 100644 --- a/sets/script.rst +++ b/sets/script.rst @@ -153,7 +153,7 @@ we have learnt * How to make sets from lists * How to input sets - * How to perform union, intersection and symmectric difference operations + * How to perform union, intersection and symmetric difference operations * How to check if a set is a subset of other * The various similarities with lists like length and containership @@ -163,5 +163,5 @@ we have learnt This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India Hope you have enjoyed and found it useful. -Thankyou +Thank you! diff --git a/sets/slides.org b/sets/slides.org new file mode 100644 index 0000000..d0b007c --- /dev/null +++ b/sets/slides.org @@ -0,0 +1,71 @@ +#+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: Sets +#+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 + - Defining Sets + - Operations on sets + +* Question 1 + Given a list of marks, ~marks = [20, 23, 22, 23, 20, 21, 23]~ list + all the duplicates +* Solution 1 + #+begin_src python + marks = [20, 23, 22, 23, 20, 21, 23] + marks_set = set(marks) + for mark in marks_set: + marks.remove(mark) + + # we are now left with only duplicates in the list marks + duplicates = set(marks) + #+end_src +* Summary + You should now be able to -- + + make sets from lists + + input sets directly + + perform operations like union, intersection, symmetric difference + + check if a subset of another + + check containership, length and other properties similar to lists +* 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 --git a/sets/slides.tex b/sets/slides.tex index df1462c..b1b2eda 100644 --- a/sets/slides.tex +++ b/sets/slides.tex @@ -1,95 +1,93 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 23:53 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Sets} +\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 Defining Sets +\item Operations on sets +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - + Given a list of marks, \texttt{marks = [20, 23, 22, 23, 20, 21, 23]} list + all the duplicates +\end{frame} \begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +\frametitle{Solution 1} +\label{sec-3} + +\lstset{language=Python} +\begin{lstlisting} +marks = [20, 23, 22, 23, 20, 21, 23] +marks_set = set(marks) +for mark in marks_set: + marks.remove(mark) + +# we are now left with only duplicates in the list marks +duplicates = set(marks) +\end{lstlisting} \end{frame} - \begin{frame} - \frametitle{Thank you!} +\frametitle{Summary} +\label{sec-4} + + You should now be able to -- +\begin{itemize} +\item make sets from lists +\item input sets directly +\item perform operations like union, intersection, symmetric difference +\item check if a subset of another +\item check containership, length and other properties similar to lists +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-5} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the diff --git a/template/slides.org b/template/slides.org new file mode 100644 index 0000000..5d2ce93 --- /dev/null +++ b/template/slides.org @@ -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 --git a/tuples/script.rst b/tuples/script.rst index 54fee50..5918643 100644 --- a/tuples/script.rst +++ b/tuples/script.rst @@ -7,6 +7,11 @@ C - D - +.. #. what are tuples +.. #. comparison with lists +.. #. why are they needed + + .. Prerequisites .. ------------- diff --git a/tuples/slides.org b/tuples/slides.org new file mode 100644 index 0000000..d1b0d6a --- /dev/null +++ b/tuples/slides.org @@ -0,0 +1,69 @@ +#+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: Getting started -- Tuples +#+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 + - what are tuples + - comparison with lists + - why are they needed +* Question 1 + ~a = 5~ and ~b = 7~. swap the values of ~a~ and ~b~ +* Solution 1 + #+begin_src python + temp = a + a = b + b = temp + + a + b + #+end_src +* Summary + You should now -- + + Be able to define tuples + + Know the similarities with lists, like -- indexing and iterability + + Know about the immutability of tuples + + Be able to swap variables in the Pythonic way + + Know about packing and unpacking of tuples +* 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 --git a/tuples/slides.tex b/tuples/slides.tex index df1462c..375ff07 100644 --- a/tuples/slides.tex +++ b/tuples/slides.tex @@ -1,95 +1,92 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-10-10 Sun 23:03 +\documentclass[presentation]{beamer} \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{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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} + +\title{Getting started -- Tuples} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + \begin{frame} - \maketitle +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item what are tuples +\item comparison with lists +\item why are they needed +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} -\begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} + \texttt{a = 5} and \texttt{b = 7}. swap the values of \texttt{a} and \texttt{b} \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} +\frametitle{Solution 1} +\label{sec-3} + +\lstset{language=Python} +\begin{lstlisting} +temp = a +a = b +b = temp + +a +b +\end{lstlisting} \end{frame} - \begin{frame} - \frametitle{Thank you!} +\frametitle{Summary} +\label{sec-4} + + You should now -- +\begin{itemize} +\item Be able to define tuples +\item Know the similarities with lists, like -- indexing and iterability +\item Know about the immutability of tuples +\item Be able to swap variables in the Pythonic way +\item Know about packing and unpacking of tuples +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-5} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the |