author | Shantanu <shantanu@fossee.in> |
Sat, 03 Oct 2009 19:39:49 +0530 | |
changeset 8 | 41bdf277c755 |
parent 5 | 838cedef5e9d |
child 26 | c72eae1c5c9d |
permissions | -rwxr-xr-x |
5
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2 |
% Tutorial slides on Python. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
3 |
% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
4 |
% Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in> |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
5 |
% Copyright (c) 2005-2008, Prabhu Ramachandran |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
6 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
7 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
8 |
\documentclass[14pt,compress]{beamer} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
9 |
%\documentclass[draft]{beamer} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
10 |
%\documentclass[compress,handout]{beamer} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
11 |
%\usepackage{pgfpages} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
12 |
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
14 |
% Modified from: generic-ornate-15min-45min.de.tex |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
15 |
\mode<presentation> |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
16 |
{ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
17 |
\usetheme{Warsaw} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
18 |
\useoutertheme{split} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
19 |
\setbeamercovered{transparent} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
20 |
} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
21 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
22 |
\usepackage[english]{babel} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
23 |
\usepackage[latin1]{inputenc} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
24 |
%\usepackage{times} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
25 |
\usepackage[T1]{fontenc} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
26 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
27 |
% Taken from Fernando's slides. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
28 |
\usepackage{ae,aecompl} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
29 |
\usepackage{mathpazo,courier,euler} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
30 |
\usepackage[scaled=.95]{helvet} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
31 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
32 |
\definecolor{darkgreen}{rgb}{0,0.5,0} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
33 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
34 |
\usepackage{listings} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
35 |
\lstset{language=Python, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
36 |
basicstyle=\ttfamily, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
37 |
commentstyle=\color{red}\itshape, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
38 |
stringstyle=\color{darkgreen}, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
39 |
showstringspaces=false, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
40 |
keywordstyle=\color{blue}\bfseries} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
41 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
42 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
43 |
% Macros |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
44 |
\setbeamercolor{emphbar}{bg=blue!20, fg=black} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
45 |
\newcommand{\emphbar}[1] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
46 |
{\begin{beamercolorbox}[rounded=true]{emphbar} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
47 |
{#1} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
48 |
\end{beamercolorbox} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
49 |
} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
50 |
\newcounter{time} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
51 |
\setcounter{time}{0} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
52 |
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
53 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
54 |
\newcommand{\typ}[1]{\texttt{#1}} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
55 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
56 |
\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
57 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
58 |
%%% This is from Fernando's setup. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
59 |
% \usepackage{color} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
60 |
% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
61 |
% % Use and configure listings package for nicely formatted code |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
62 |
% \usepackage{listings} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
63 |
% \lstset{ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
64 |
% language=Python, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
65 |
% basicstyle=\small\ttfamily, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
66 |
% commentstyle=\ttfamily\color{blue}, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
67 |
% stringstyle=\ttfamily\color{orange}, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
68 |
% showstringspaces=false, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
69 |
% breaklines=true, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
70 |
% postbreak = \space\dots |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
71 |
% } |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
72 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
73 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
74 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
75 |
% Title page |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
76 |
\title[Basic Python]{Python:\\A great programming toolkit} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
77 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
78 |
\author[Asokan \& Prabhu] {Asokan Pichai\\Prabhu Ramachandran} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
79 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
80 |
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
81 |
\date[] {25, July 2009} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
82 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
83 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
84 |
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
85 |
%\logo{\pgfuseimage{iitmlogo}} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
86 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
87 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
88 |
%% Delete this, if you do not want the table of contents to pop up at |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
89 |
%% the beginning of each subsection: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
90 |
\AtBeginSubsection[] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
91 |
{ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
92 |
\begin{frame}<beamer> |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
93 |
\frametitle{Outline} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
94 |
\tableofcontents[currentsection,currentsubsection] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
95 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
96 |
} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
97 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
98 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
99 |
% If you wish to uncover everything in a step-wise fashion, uncomment |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
100 |
% the following command: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
101 |
%\beamerdefaultoverlayspecification{<+->} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
102 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
103 |
%\includeonlyframes{current,current1,current2,current3,current4,current5,current6} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
104 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
105 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
106 |
% DOCUMENT STARTS |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
107 |
\begin{document} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
108 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
109 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
110 |
\titlepage |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
111 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
112 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
113 |
{Acknowledgements} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
114 |
\begin{center} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
115 |
This program is conducted by\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
116 |
IIT, Bombay\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
117 |
through CDEEP\\as part of the open source initiatives\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
118 |
under the aegis of\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
119 |
\alert{National Mission on Education through ICT,} \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
120 |
Ministry of HRD. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
121 |
\end{center} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
122 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
123 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
124 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
125 |
\frametitle{Outline} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
126 |
\tableofcontents |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
127 |
% You might wish to add the option [pausesections] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
128 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
129 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
130 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
131 |
% TODO |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
132 |
% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
133 |
% * Add slide on Python packages (modules) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
134 |
% * Add slides on reference counting. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
135 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
136 |
\section{Agenda} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
137 |
\begin{frame}{About the Workshop} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
138 |
\begin{description} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
139 |
\item[Session 1] Sat 14:00--15:55 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
140 |
\item[Session 2] Sat 16:05--18:00 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
141 |
\item[Session 3] Sun 14:00--15:55 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
142 |
\item[Session 4] Sun 16:05--18:00 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
143 |
\end{description} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
144 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
145 |
\begin{block}{Goal of the workshop} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
146 |
At the end of this program, successful participants will be able to use python as their scripting and problem solving language. Aimed at Engg. students--focus on basic numerics and plotting-- but should serve a similar purpose for others. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
147 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
148 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
149 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
150 |
\begin{frame}{Checklist} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
151 |
Let us verify that all of us are having the same (similar) tools and environment |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
152 |
\begin{description} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
153 |
\item[python] Type python at the command line. Do you see version 2.5 or later? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
154 |
\item[IPython] Is IPython available? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
155 |
\item[Editor] Which editor? scite, vim, emacs, \ldots |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
156 |
\end{description} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
157 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
158 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
159 |
\section{Overview} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
160 |
\begin{frame}{Session 1} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
161 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
162 |
\item Introduction and motivation |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
163 |
\item Using the interpreter(s) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
164 |
\item Basic data types: int, float, string |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
165 |
\item Basic data structures: list |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
166 |
\item Basic console IO: \texttt{raw\_input(), print} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
167 |
\item Basic control flow: \texttt{if, while} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
168 |
\item Problem set 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
169 |
\item Functions $\rightarrow$ Problem set 2 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
170 |
\item lists, \texttt{for} $\rightarrow$ Problem set 3 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
171 |
\item IO, Modules $\rightarrow$ Problem sets 4,5, \ldots |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
172 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
173 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
174 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
175 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
176 |
\frametitle{Introduction} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
177 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
178 |
\item Creator and BDFL: Guido van Rossum |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
179 |
\item Conceived in December 1989 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
180 |
\item ``Python'' as in Monty Python's Flying Circus |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
181 |
\item Current stable version of Python is 2.6.x |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
182 |
\item PSF license (like BSD: no strings attached) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
183 |
\item Highly cross platform |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
184 |
\item Runs on the Nokia series 60! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
185 |
\item \alert{Philosophy:} Simple and complete by design |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
186 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
187 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
188 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
189 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
190 |
\frametitle{Resources} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
191 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
192 |
\item Part of many GNU/Linux distributions |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
193 |
\item Web: \url{http://www.python.org} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
194 |
\item Doc: \url{http://www.python.org/doc} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
195 |
\item Free Tutorials: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
196 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
197 |
\item Official Python tutorial: \url{http://docs.python.org/tut/tut.html} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
198 |
\item Byte of Python: \url{http://www.byteofpython.info/} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
199 |
\item Dive into Python: \url{http://diveintopython.org/} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
200 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
201 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
202 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
203 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
204 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
205 |
\frametitle{Why Python?} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
206 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
207 |
\item Designed to be readable and easy to use |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
208 |
\item High level, interpreted, modular, OO |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
209 |
\item Much faster development cycle |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
210 |
\item Powerful interactive environment |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
211 |
\item Rapid application development |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
212 |
\item Rich standard library and modules |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
213 |
\item Interfaces well with C++, C and FORTRAN |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
214 |
\item \alert{More than a math package $\Rightarrow$ some extra work compared to math packages} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
215 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
216 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
217 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
218 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
219 |
\frametitle{Use cases} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
220 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
221 |
\item NASA: Space Shuttle Mission Design |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
222 |
\item AstraZeneca: Collaborative Drug Discovery |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
223 |
\item ForecastWatch.com: Helps Meteorologists |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
224 |
\item Industrial Light \& Magic: Runs on Python |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
225 |
\item Zope: Commercial grade Toolkit |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
226 |
\item Plone: Professional high feature CMS |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
227 |
\item RedHat: install scripts, sys-admin tools |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
228 |
\item Django: A great web application framework |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
229 |
\item Google: A strong python shop |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
230 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
231 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
232 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
233 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
234 |
\frametitle{To sum up, python is\ldots} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
235 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
236 |
\item dynamically typed, interpreted $\rightarrow$ rapid testing/prototyping |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
237 |
\item powerful, very high level |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
238 |
\item has full introspection |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
239 |
\item Did we mention powerful? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
240 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
241 |
\begin{block}{But \ldots} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
242 |
may be wanting in performance. specialised resources such as SWIG, \alert{Cython} are available |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
243 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
244 |
\inctime{15} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
245 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
246 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
247 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
248 |
% TIME: 15 m, running 15m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
249 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
250 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
251 |
\section{Python} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
252 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
253 |
\subsection{Getting Started} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
254 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
255 |
\begin{frame}[fragile]{At the prompt, type the following} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
256 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
257 |
>>> print 'Hello Python' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
258 |
>>> print 3124 * 126789 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
259 |
>>> 1786 % 12 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
260 |
>>> 3124 * 126789 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
261 |
>>> a = 3124 * 126789 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
262 |
>>> big = 12345678901234567890 ** 3 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
263 |
>>> verybig = big * big * big * big |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
264 |
>>> 12345**6, 12345**67, 12345**678 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
265 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
266 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
267 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
268 |
\begin{frame}[fragile]{At the prompt, type the following} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
269 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
270 |
>>> s = 'Hello ' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
271 |
>>> p = 'World' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
272 |
>>> s + p |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
273 |
>>> s * 12 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
274 |
>>> s * s |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
275 |
>>> s + p * 12, (s + p)* 12 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
276 |
>>> s * 12 + p * 12 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
277 |
>>> 12 * s |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
278 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
279 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
280 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
281 |
\begin{frame}[fragile]{At the prompt, type the following} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
282 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
283 |
>>> 17/2 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
284 |
>>> 17/2.0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
285 |
>>> 17.0/2 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
286 |
>>> 17.0/8.5 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
287 |
>>> int(17/2.0) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
288 |
>>> float(17/2) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
289 |
>>> str(17/2.0) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
290 |
>>> round( 7.5 ) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
291 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
292 |
\begin{block}{Mini exercise} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
293 |
Round a float to the nearest integer, using \texttt{int()}? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
294 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
295 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
296 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
297 |
\begin{frame}{Midi exercises} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
298 |
\begin{center} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
299 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
300 |
\item What does this do? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
301 |
\item \texttt{round(amount * 10) /10.0 } |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
302 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
303 |
\end{center} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
304 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
305 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
306 |
\begin{frame}{More exercises?} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
307 |
\begin{center} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
308 |
\begin{block}{Round sums} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
309 |
How to round a number to the nearest 5 paise?\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
310 |
\begin{description} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
311 |
\item[Remember] 17.23 $\rightarrow$ 17.25,\\ while 17.22 $\rightarrow$ 17.20\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
312 |
\end{description} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
313 |
How to round a number to the nearest 20 paise? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
314 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
315 |
\end{center} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
316 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
317 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
318 |
\begin{frame}[fragile] {A question of good style} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
319 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
320 |
amount = 12.68 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
321 |
denom = 0.05 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
322 |
nCoins = round(amount/denom) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
323 |
rAmount = nCoins * denom |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
324 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
325 |
\pause |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
326 |
\begin{block}{Style Rule \#1} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
327 |
Naming is 80\% of programming |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
328 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
329 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
330 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
331 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
332 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
333 |
\frametitle{Odds and ends} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
334 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
335 |
\item Case sensitive |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
336 |
\item Dynamically typed $\Rightarrow$ need not specify a type |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
337 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
338 |
a = 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
339 |
a = 1.1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
340 |
a = "Now I am a string!" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
341 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
342 |
\item Comments: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
343 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
344 |
a = 1 # In-line comments |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
345 |
# Comment in a line to itself. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
346 |
a = "# This is not a comment!" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
347 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
348 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
349 |
\inctime{15} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
350 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
351 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
352 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
353 |
% TIME: 15 m, running 30m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
354 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
355 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
356 |
\subsection{Data types} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
357 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
358 |
\frametitle{Basic types} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
359 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
360 |
\item numbers: float, int, long, complex |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
361 |
\item strings |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
362 |
\item boolean |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
363 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
364 |
\begin{block}{Also to be discussed later} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
365 |
tuples, lists, dictionaries, functions, objects\ldots |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
366 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
367 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
368 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
369 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
370 |
\frametitle{Numbers} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
371 |
\vspace*{-0.25in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
372 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
373 |
>>> a = 1 # Int. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
374 |
>>> l = 1000000L # Long |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
375 |
>>> e = 1.01325e5 # float |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
376 |
>>> f = 3.14159 # float |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
377 |
>>> c = 1+1j # Complex! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
378 |
>>> print f*c/a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
379 |
(3.14159+3.14159j) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
380 |
>>> print c.real, c.imag |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
381 |
1.0 1.0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
382 |
>>> abs(c) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
383 |
1.4142135623730951 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
384 |
>>> abs( 8 - 9.5 ) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
385 |
1.5 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
386 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
387 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
388 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
389 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
390 |
\frametitle{Boolean} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
391 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
392 |
>>> t = True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
393 |
>>> f = not t |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
394 |
False |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
395 |
>>> f or t |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
396 |
True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
397 |
>>> f and t |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
398 |
False |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
399 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
400 |
\begin{block}{Try:} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
401 |
NOT True\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
402 |
not TRUE |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
403 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
404 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
405 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
406 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
407 |
\frametitle{Relational and logical operators} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
408 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
409 |
>>> a, b, c = -1, 0, 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
410 |
>>> a == b |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
411 |
False |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
412 |
>>> a <= b |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
413 |
True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
414 |
>>> a + b != c |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
415 |
True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
416 |
>>> a < b < c |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
417 |
True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
418 |
>>> c >= a + b |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
419 |
True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
420 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
421 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
422 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
423 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
424 |
\frametitle{Strings} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
425 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
426 |
s = 'this is a string' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
427 |
s = 'This one has "quotes" inside!' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
428 |
s = "I have 'single-quotes' inside!" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
429 |
l = "A string spanning many lines\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
430 |
one more line\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
431 |
yet another" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
432 |
t = """A triple quoted string does |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
433 |
not need to be escaped at the end and |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
434 |
"can have nested quotes" etc.""" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
435 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
436 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
437 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
438 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
439 |
\frametitle{More Strings} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
440 |
\vspace*{-0.2in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
441 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
442 |
>>> w = "hello" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
443 |
>>> print w[0] + w[2] + w[-1] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
444 |
hlo |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
445 |
>>> len(w) # guess what |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
446 |
5 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
447 |
>>> s = u'Unicode strings!' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
448 |
>>> # Raw strings (note the leading 'r') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
449 |
... r_s = r'A string $\alpha \nu$' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
450 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
451 |
\pause |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
452 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
453 |
>>> w[0] = 'H' # Can't do that! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
454 |
Traceback (most recent call last): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
455 |
File "<stdin>", line 1, in ? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
456 |
TypeError: object does not support item assignment |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
457 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
458 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
459 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
460 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
461 |
\frametitle{Let us switch to IPython} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
462 |
Why? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
463 |
\begin{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
464 |
{Better help (and a lot more)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
465 |
Tab completion\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
466 |
?\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
467 |
.?\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
468 |
object.function? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
469 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
470 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
471 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
472 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
473 |
\frametitle{More on strings} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
474 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
475 |
In [1]: a = 'hello world' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
476 |
In [2]: a.startswith('hell') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
477 |
Out[2]: True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
478 |
In [3]: a.endswith('ld') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
479 |
Out[3]: True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
480 |
In [4]: a.upper() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
481 |
Out[4]: 'HELLO WORLD' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
482 |
In [5]: a.upper().lower() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
483 |
Out[5]: 'hello world' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
484 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
485 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
486 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
487 |
\begin{frame}[fragile]{Still with strings} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
488 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
489 |
In [6]: a.split() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
490 |
Out[6]: ['hello', 'world'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
491 |
In [7]: ''.join(['a', 'b', 'c']) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
492 |
Out[7]: 'abc' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
493 |
In [8] 'd' in ''.join( 'a', 'b', 'c') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
494 |
Out[8]: False |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
495 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
496 |
\begin{block}{Try:} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
497 |
\texttt{a.split( 'o' )}\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
498 |
\texttt{'x'.join( a.split( 'o' ) )} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
499 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
500 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
501 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
502 |
\begin{frame}[fragile]{Surprise! strings!!} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
503 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
504 |
In [11]: x, y = 1, 1.2 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
505 |
In [12]: 'x is %s, y is %s' %(x, y) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
506 |
Out[12]: 'x is 1, y is 1.234' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
507 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
508 |
\begin{block}{Try:} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
509 |
\texttt{'x is \%d, y is \%f' \%(x, y) }\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
510 |
\texttt{'x is \%3d, y is \%4.2f' \%(x, y) } |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
511 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
512 |
\small |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
513 |
\url{docs.python.org/lib/typesseq-strings.html}\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
514 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
515 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
516 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
517 |
{Interlude} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
518 |
\begin{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
519 |
{A classic problem} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
520 |
How to interchange values of two variables? Please note that the type of either variable is unknown and it is not necessary that both be of the same type even! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
521 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
522 |
\inctime{30} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
523 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
524 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
525 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
526 |
% TIME: 25 m+ Interlude break 5 mins, running 60m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
527 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
528 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
529 |
\subsection{Control flow} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
530 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
531 |
\frametitle{Control flow constructs} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
532 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
533 |
\item \kwrd{if/elif/else}: branching |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
534 |
\item \kwrd{while}: looping |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
535 |
\item \kwrd{for}: iterating |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
536 |
\item \kwrd{break, continue}: modify loop |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
537 |
\item \kwrd{pass}: syntactic filler |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
538 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
539 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
540 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
541 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
542 |
\frametitle{Basic conditional flow} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
543 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
544 |
In [21]: a = 7 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
545 |
In [22]: b = 8 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
546 |
In [23]: if a > b: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
547 |
....: print 'Hello' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
548 |
....: else: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
549 |
....: print 'World' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
550 |
....: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
551 |
....: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
552 |
World |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
553 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
554 |
Let us switch to creating a file |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
555 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
556 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
557 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
558 |
{Creating python files} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
559 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
560 |
\item aka scripts |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
561 |
\item use your editor |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
562 |
\item Note that white space is the way to specify blocks! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
563 |
\item extension \typ{.py} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
564 |
\item run with \texttt{python hello.py} at the command line |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
565 |
\item in IPython\ldots |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
566 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
567 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
568 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
569 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
570 |
\frametitle{\typ{If...elif...else} example} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
571 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
572 |
x = int(raw_input("Enter an integer:")) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
573 |
if x < 0: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
574 |
print 'Be positive!' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
575 |
elif x == 0: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
576 |
print 'Zero' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
577 |
elif x == 1: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
578 |
print 'Single' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
579 |
else: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
580 |
print 'More' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
581 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
582 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
583 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
584 |
\begin{frame}{Simple IO} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
585 |
\begin{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
586 |
{Console Input} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
587 |
\texttt{raw\_input(}) waits for user input.\\Prompt string is optional.\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
588 |
All keystrokes are Strings!\\\texttt{int()} converts string to int. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
589 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
590 |
\begin{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
591 |
{Console output} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
592 |
\texttt{print} is straight forward. Major point to remember is the distinction between \texttt{print x} and \texttt{print x,} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
593 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
594 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
595 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
596 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
597 |
\frametitle{Basic looping} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
598 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
599 |
# Fibonacci series: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
600 |
# the sum of two elements |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
601 |
# defines the next |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
602 |
a, b = 0, 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
603 |
while b < 10: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
604 |
print b, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
605 |
a, b = b, a + b |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
606 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
607 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
608 |
\typ{1 1 2 3 5 8}\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
609 |
\alert{Recall it is easy to write infinite loops with \kwrd{while}} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
610 |
\inctime{20} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
611 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
612 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
613 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
614 |
% TIME: 20 m, running 80m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
615 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
616 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
617 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
618 |
\frametitle{Problem set 1} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
619 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
620 |
\item All the problems can be\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
621 |
solved using \kwrd{if} and \kwrd{while} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
622 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
623 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
624 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
625 |
\begin{frame}{Problem 1.1} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
626 |
Write a program that displays all three digit numbers that are equal to the sum of the cubes of their digits. That is, print numbers $abc$ that have the property $abc = a^3 + b^3 + c^3$\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
627 |
These are called $Armstrong$ numbers. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
628 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
629 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
630 |
\begin{frame}{Problem 1.2 - Collatz sequence} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
631 |
\begin{enumerate} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
632 |
\item Start with an arbitrary (positive) integer. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
633 |
\item If the number is even, divide by 2; if the number is odd multiply by 3 and add 1. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
634 |
\item Repeat the procedure with the new number. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
635 |
\item It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
636 |
\end{enumerate} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
637 |
Write a program that accepts the starting value and prints out the Collatz sequence. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
638 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
639 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
640 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
641 |
\begin{frame}{Problem 1.3 - Kaprekar's constant} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
642 |
\begin{enumerate} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
643 |
\item Take a four digit number--with at least two digits different. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
644 |
\item Arrange the digits in ascending and descending order, giving A and D respectively. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
645 |
\item Leave leading zeros in A! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
646 |
\item Subtract A from D. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
647 |
\item With the result, repeat from step 2. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
648 |
\end{enumerate} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
649 |
Write a program to accept a 4-digit number and display the progression to Kaprekar's constant. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
650 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
651 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
652 |
\begin{frame}[fragile]{Problem 1.4} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
653 |
Write a program that prints the following pyramid on the screen. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
654 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
655 |
1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
656 |
2 2 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
657 |
3 3 3 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
658 |
4 4 4 4 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
659 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
660 |
The number of lines must be obtained from the user as input.\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
661 |
\pause |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
662 |
When can your code fail? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
663 |
\only<2->{\inctime{25}} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
664 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
665 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
666 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
667 |
% TIME: 25 m, running 105m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
668 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
669 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
670 |
\subsection{Functions} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
671 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
672 |
\frametitle{Functions: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
673 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
674 |
def signum( r ): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
675 |
"""returns 0 if r is zero |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
676 |
-1 if r is negative |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
677 |
+1 if r is positive""" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
678 |
if r < 0: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
679 |
return -1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
680 |
elif r > 0: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
681 |
return 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
682 |
else: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
683 |
return 0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
684 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
685 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
686 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
687 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
688 |
\frametitle{Functions: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
689 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
690 |
def pad( n, size ): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
691 |
"""pads integer n with spaces |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
692 |
into a string of length size |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
693 |
""" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
694 |
SPACE = ' ' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
695 |
s = str( n ) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
696 |
padSize = size - len( s ) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
697 |
return padSize * SPACE + s |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
698 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
699 |
\pause |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
700 |
What about \%3d? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
701 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
702 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
703 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
704 |
{What does this function do?} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
705 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
706 |
def what( n ): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
707 |
if n < 0: n = -n |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
708 |
while n > 0: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
709 |
if n % 2 == 1: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
710 |
return False |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
711 |
n /= 10 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
712 |
return True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
713 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
714 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
715 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
716 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
717 |
{What does this function do?} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
718 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
719 |
def what( n ): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
720 |
i = 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
721 |
while i * i < n: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
722 |
i += 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
723 |
return i * i == n, i |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
724 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
725 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
726 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
727 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
728 |
{What does this function do?} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
729 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
730 |
def what( n, x ): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
731 |
z = 1.0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
732 |
if n < 0: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
733 |
x = 1.0 / x |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
734 |
n = -n |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
735 |
while n > 0: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
736 |
if n % 2 == 1: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
737 |
z *= x |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
738 |
n /= 2 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
739 |
x *= x |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
740 |
return z |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
741 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
742 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
743 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
744 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
745 |
{Before writing a function} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
746 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
747 |
\item Builtin functions for various and sundry |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
748 |
\item \typ{abs, any, all, len, max, min} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
749 |
\item \typ{pow, range, sum, type} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
750 |
\item Refer here: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
751 |
\url{http://docs.python.org/library/functions.html} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
752 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
753 |
\inctime{15} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
754 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
755 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
756 |
% TIME: 15 m, running 120m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
757 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
758 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
759 |
\begin{frame}{Problem set 2} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
760 |
The focus is on writing functions and calling them. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
761 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
762 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
763 |
\begin{frame}{Problem 2.1} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
764 |
Write a function to return the gcd of two numbers. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
765 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
766 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
767 |
\begin{frame}{Problem 2.2} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
768 |
A pythagorean triad $(a,b,c)$ has the property $a^2 + b^2 = c^2$.\\By primitive we mean triads that do not `depend' on others. For example, (4,3,5) is a variant of (3,4,5) and hence is not primitive. And (10,24,26) is easily derived from (5,12,13) and should not be displayed by our program. \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
769 |
Write a program to print primitive pythagorean triads. The program should generate all triads with a, b values in the range 0---100 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
770 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
771 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
772 |
\begin{frame}{Problem 2.3} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
773 |
Write a program that generates a list of all four digit numbers that have all their digits even and are perfect squares.\\For example, the output should include 6400 but not 8100 (one digit is odd) or 4248 (not a perfect square). |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
774 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
775 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
776 |
\begin{frame}{Problem 2.4} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
777 |
The aliquot of a number is defined as: the sum of the \emph{proper} divisors of the number. For example, the aliquot(12) = 1 + 2 + 3 + 4 + 6 = 16.\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
778 |
Write a function that returns the aliquot number of a given number. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
779 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
780 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
781 |
\begin{frame}{Problem 2.5} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
782 |
A pair of numbers (a, b) is said to be \alert{amicable} if the aliquot number of a is b and the aliquot number of b is a.\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
783 |
Example: \texttt{220, 284}\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
784 |
Write a program that prints all five digit amicable pairs. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
785 |
\inctime{30} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
786 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
787 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
788 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
789 |
% TIME: 30 m, running 150m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
790 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
791 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
792 |
\subsection{Lists} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
793 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
794 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
795 |
\frametitle{List creation and indexing} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
796 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
797 |
>>> a = [] # An empty list. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
798 |
>>> a = [1, 2, 3, 4] # More useful. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
799 |
>>> len(a) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
800 |
4 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
801 |
>>> a[0] + a[1] + a[2] + a[-1] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
802 |
10 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
803 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
804 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
805 |
\item Indices start with ? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
806 |
\item Negative indices indicate ? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
807 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
808 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
809 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
810 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
811 |
\frametitle{List: slices} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
812 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
813 |
\item Slicing is a basic operation |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
814 |
\item \typ{list[initial:final:step]} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
815 |
\item The step is optional |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
816 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
817 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
818 |
>>> a[1:3] # A slice. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
819 |
[2, 3] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
820 |
>>> a[1:-1] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
821 |
[2, 3, 4] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
822 |
>>> a[1:] == a[1:-1] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
823 |
False |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
824 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
825 |
Explain last result |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
826 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
827 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
828 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
829 |
\frametitle{List: more slices} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
830 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
831 |
>>> a[0:-1:2] # Notice the step! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
832 |
[1, 3] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
833 |
>>> a[::2] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
834 |
[1, 3] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
835 |
>>> a[-1::-1] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
836 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
837 |
What do you think the last one will do? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
838 |
\emphbar{Note: Strings also use same indexing and slicing.} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
839 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
840 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
841 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
842 |
\frametitle{List: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
843 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
844 |
>>> a = [1, 2, 3, 4] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
845 |
>>> a[:2] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
846 |
[1, 3] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
847 |
>>> a[0:-1:2] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
848 |
[1, 3] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
849 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
850 |
\pause |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
851 |
\alert{Lists are mutable (unlike strings)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
852 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
853 |
>>> a[1] = 20 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
854 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
855 |
[1, 20, 3, 4] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
856 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
857 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
858 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
859 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
860 |
\frametitle{Lists are mutable and heterogenous} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
861 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
862 |
>>> a = ['spam', 'eggs', 100, 1234] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
863 |
>>> a[2] = a[2] + 23 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
864 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
865 |
['spam', 'eggs', 123, 1234] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
866 |
>>> a[0:2] = [1, 12] # Replace items |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
867 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
868 |
[1, 12, 123, 1234] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
869 |
>>> a[0:2] = [] # Remove items |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
870 |
>>> a.append( 12345 ) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
871 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
872 |
[123, 1234, 12345] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
873 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
874 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
875 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
876 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
877 |
\frametitle{List methods} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
878 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
879 |
>>> a = ['spam', 'eggs', 1, 12] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
880 |
>>> a.reverse() # in situ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
881 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
882 |
[12, 1, 'eggs', 'spam'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
883 |
>>> a.append(['x', 1]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
884 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
885 |
[12, 1, 'eggs', 'spam', ['x', 1]] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
886 |
>>> a.extend([1,2]) # Extend the list. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
887 |
>>> a.remove( 'spam' ) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
888 |
>>> a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
889 |
[12, 1, 'eggs', ['x', 1], 1, 2] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
890 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
891 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
892 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
893 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
894 |
\frametitle{List containership} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
895 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
896 |
>>> a = ['cat', 'dog', 'rat', 'croc'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
897 |
>>> 'dog' in a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
898 |
True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
899 |
>>> 'snake' in a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
900 |
False |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
901 |
>>> 'snake' not in a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
902 |
True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
903 |
>>> 'ell' in 'hello world' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
904 |
True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
905 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
906 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
907 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
908 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
909 |
\frametitle{Tuples: immutable} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
910 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
911 |
>>> t = (0, 1, 2) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
912 |
>>> print t[0], t[1], t[2], t[-1] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
913 |
0 1 2 2 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
914 |
>>> t[0] = 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
915 |
Traceback (most recent call last): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
916 |
File "<stdin>", line 1, in ? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
917 |
TypeError: object does not support item |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
918 |
assignment |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
919 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
920 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
921 |
\item Multiple return values are actually a tuple. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
922 |
\item Exchange is tuple (un)packing |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
923 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
924 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
925 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
926 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
927 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
928 |
\frametitle{\typ{range()} function} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
929 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
930 |
>>> range(7) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
931 |
[0, 1, 2, 3, 4, 5, 6] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
932 |
>>> range( 3, 9) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
933 |
[3, 4, 5, 6, 7, 8] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
934 |
>>> range( 4, 17, 3) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
935 |
[4, 7, 10, 13, 16] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
936 |
>>> range( 5, 1, -1) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
937 |
[5, 4, 3, 2] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
938 |
>>> range( 8, 12, -1) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
939 |
[] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
940 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
941 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
942 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
943 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
944 |
\frametitle{\typ{for\ldots range(\ldots)} idiom} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
945 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
946 |
In [83]: for i in range(5): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
947 |
....: print i, i * i |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
948 |
....: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
949 |
....: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
950 |
0 0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
951 |
1 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
952 |
2 4 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
953 |
3 9 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
954 |
4 16 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
955 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
956 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
957 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
958 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
959 |
\frametitle{\typ{for}: the list companion} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
960 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
961 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
962 |
In [84]: a = ['a', 'b', 'c'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
963 |
In [85]: for x in a: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
964 |
....: print x, chr( ord(x) + 10 ) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
965 |
....: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
966 |
a k |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
967 |
b l |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
968 |
c m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
969 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
970 |
Iterating over the list and not the index + reference\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
971 |
what if you want the index? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
972 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
973 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
974 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
975 |
\frametitle{\typ{for}: the list companion} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
976 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
977 |
In [89]: for p, ch in enumerate( a ): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
978 |
....: print p, ch |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
979 |
....: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
980 |
....: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
981 |
0 a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
982 |
1 b |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
983 |
2 c |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
984 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
985 |
Try: \typ{print enumerate(a)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
986 |
\inctime{20} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
987 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
988 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
989 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
990 |
% TIME: 20 m, running 170m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
991 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
992 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
993 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
994 |
{Problem set 3} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
995 |
As you can guess, idea is to use \kwrd{for}! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
996 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
997 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
998 |
\begin{frame}{Problem 3.1} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
999 |
Which of the earlier problems is simpler when we use \kwrd{for} instead of \kwrd{while}? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1000 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1001 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1002 |
\begin{frame}{Problem 3.2} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1003 |
Given an empty chessboard and one Bishop placed in any square, say (r, c), generate the list of all squares the Bishop could move to. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1004 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1005 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1006 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1007 |
\frametitle{Problem 3.3} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1008 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1009 |
Given two real numbers \typ{a, b}, and an integer \typ{N}, write a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1010 |
function named \typ{linspace( a, b, N)} that returns an ordered list |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1011 |
of \typ{N} points starting with \typ{a} and ending in \typ{b} and |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1012 |
equally spaced.\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1013 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1014 |
For example, \typ{linspace(0, 5, 11)}, should return, \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1015 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1016 |
[ 0.0 , 0.5, 1.0 , 1.5, 2.0 , 2.5, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1017 |
3.0 , 3.5, 4.0 , 4.5, 5.0 ] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1018 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1019 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1020 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1021 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1022 |
\frametitle{Problem 3.4a (optional)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1023 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1024 |
Use the \typ{linspace} function and generate a list of N tuples of the form\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1025 |
\typ{[($x_1$,f($x_1$)),($x_2$,f($x_2$)),\ldots,($x_N$,f($x_N$))]}\\for the following functions,\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1026 |
\item \typ{f(x) = sin(x)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1027 |
\item \typ{f(x) = sin(x) + sin(10*x)}. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1028 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1029 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1030 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1031 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1032 |
\frametitle{Problem 3.4b (optional)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1033 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1034 |
Using the tuples generated earlier, determine the intervals where the roots of the functions lie. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1035 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1036 |
\inctime{15} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1037 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1038 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1039 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1040 |
% TIME: 15 m, running 185m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1041 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1042 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1043 |
\subsection{IO} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1044 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1045 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1046 |
\frametitle{Simple tokenizing and parsing} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1047 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1048 |
s = """The quick brown fox jumped |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1049 |
over the lazy dog""" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1050 |
for word in s.split(): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1051 |
print word.capitalize() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1052 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1053 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1054 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1055 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1056 |
\frametitle{Problem 4.1} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1057 |
Given a string like, ``1, 3-7, 12, 15, 18-21'', produce the list \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1058 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1059 |
[1,3,4,5,6,7,12,15,18,19,20,21] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1060 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1061 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1062 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1063 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1064 |
\frametitle{File handling} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1065 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1066 |
>>> f = open('/path/to/file_name') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1067 |
>>> data = f.read() # Read entire file. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1068 |
>>> line = f.readline() # Read one line. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1069 |
>>> f.close() # close the file. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1070 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1071 |
Writing files |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1072 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1073 |
>>> f = open('/path/to/file_name', 'w') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1074 |
>>> f.write('hello world\n') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1075 |
>>> f.close() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1076 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1077 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1078 |
\item Everything read or written is a string |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1079 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1080 |
\emphbar{Try \typ{file?} for more help} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1081 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1082 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1083 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1084 |
\frametitle{File and \kwrd{for}} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1085 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1086 |
>>> f = open('/path/to/file_name') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1087 |
>>> for line in f: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1088 |
... print line |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1089 |
... |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1090 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1091 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1092 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1093 |
\begin{frame}{Problem 4.2} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1094 |
The given file has lakhs of records in the form:\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1095 |
\typ{RGN;ID;NAME;MARK1;\ldots;MARK5;TOTAL;PFW}\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1096 |
Some entries may be empty. Read the data from this file and print the |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1097 |
name of the student with the maximum total marks. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1098 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1099 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1100 |
\begin{frame}{Problem 4.3} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1101 |
For the same data file compute the average marks in different |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1102 |
subjects, the student with the maximum mark in each subject and also |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1103 |
the standard deviation of the marks. Do this efficiently. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1104 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1105 |
\inctime{20} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1106 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1107 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1108 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1109 |
% TIME: 20 m, running 205m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1110 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1111 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1112 |
\subsection{Modules} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1113 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1114 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1115 |
{Modules} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1116 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1117 |
>>> sqrt(2) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1118 |
Traceback (most recent call last): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1119 |
File "<stdin>", line 1, in <module> |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1120 |
NameError: name 'sqrt' is not defined |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1121 |
>>> import math |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1122 |
>>> math.sqrt(2) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1123 |
1.4142135623730951 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1124 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1125 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1126 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1127 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1128 |
{Modules} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1129 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1130 |
\item The \kwrd{import} keyword ``loads'' a module |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1131 |
\item One can also use: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1132 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1133 |
>>> from math import sqrt |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1134 |
>>> from math import * |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1135 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1136 |
\item What is the difference? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1137 |
\item \alert{Use the later only in interactive mode} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1138 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1139 |
\emphbar{Package hierarchies} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1140 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1141 |
>>> from os.path import exists |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1142 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1143 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1144 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1145 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1146 |
\frametitle{Modules: Standard library} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1147 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1148 |
\item Very powerful, ``Batteries included'' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1149 |
\item Some standard modules: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1150 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1151 |
\item Math: \typ{math}, \typ{random} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1152 |
\item Internet access: \typ{urllib2}, \typ{smtplib} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1153 |
\item System, Command line arguments: \typ{sys} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1154 |
\item Operating system interface: \typ{os} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1155 |
\item Regular expressions: \typ{re} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1156 |
\item Compression: \typ{gzip}, \typ{zipfile}, and \typ{tarfile} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1157 |
\item And a whole lot more! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1158 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1159 |
\item Check out the Python Library reference: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1160 |
\url{http://docs.python.org/library/} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1161 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1162 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1163 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1164 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1165 |
{Modules of special interest} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1166 |
\begin{description}[matplotlibfor2d] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1167 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1168 |
\item[\typ{numpy}] Efficient, powerful numeric arrays |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1169 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1170 |
\item[\typ{matplotlib}] Easy, interactive, 2D plotting |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1171 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1172 |
\item[\typ{scipy}] statistics, optimization, integration, linear |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1173 |
algebra, Fourier transforms, signal and image processing, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1174 |
genetic algorithms, ODE solvers, special functions, and more |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1175 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1176 |
\item[Mayavi] Easy, interactive, 3D plotting |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1177 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1178 |
\end{description} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1179 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1180 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1181 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1182 |
{Creating your own modules} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1183 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1184 |
\item Define variables, functions and classes in a file with a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1185 |
\typ{.py} extension |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1186 |
\item This file becomes a module! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1187 |
\item Accessible when in the current directory |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1188 |
\item Use \typ{cd} in IPython to change directory |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1189 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1190 |
\item Naming your module |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1191 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1192 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1193 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1194 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1195 |
\frametitle{Modules: example} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1196 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1197 |
# --- arith.py --- |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1198 |
def gcd(a, b): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1199 |
if a%b == 0: return b |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1200 |
return gcd(b, a%b) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1201 |
def lcm(a, b): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1202 |
return a*b/gcd(a, b) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1203 |
# ------------------ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1204 |
>>> import arith |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1205 |
>>> arith.gcd(26, 65) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1206 |
13 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1207 |
>>> arith.lcm(26, 65) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1208 |
130 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1209 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1210 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1211 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1212 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1213 |
\frametitle{Problem 5.1} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1214 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1215 |
Put all the functions you have written so far as part of the problems |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1216 |
into one module called \typ{iitb.py} and use this module from IPython. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1217 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1218 |
\inctime{20} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1219 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1220 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1221 |
% TIME: 20 m, running 225m |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1222 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1223 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1224 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1225 |
\frametitle{Did we meet the goal?} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1226 |
\tableofcontents |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1227 |
% You might wish to add the option [pausesections] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1228 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1229 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1230 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1231 |
{Tomorrow} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1232 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1233 |
\item Plotting: 2D, 3D |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1234 |
\item NumPy, SciPy |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1235 |
\item Dictionary, Set |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1236 |
\item Debugging |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1237 |
\item Testing |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1238 |
\item \ldots |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1239 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1240 |
11:30--13:00 Discussion of answers to problems OPTIONAL |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1241 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1242 |
\end{document} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1243 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1244 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1245 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1246 |
\frametitle{More on functions} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1247 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1248 |
\item Support default and keyword arguments |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1249 |
\item Scope of variables in the function is local |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1250 |
\item Mutable items are \alert{passed by reference} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1251 |
\item First line after definition may be a documentation string |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1252 |
(\alert{recommended!}) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1253 |
\item Function definition and execution defines a name bound to the |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1254 |
function |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1255 |
\item You \emph{can} assign a variable to a function! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1256 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1257 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1258 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1259 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1260 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1261 |
\frametitle{Functions: default arguments} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1262 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1263 |
def ask_ok(prompt, retries=4, complaint='Yes or no!'): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1264 |
while True: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1265 |
ok = raw_input(prompt) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1266 |
if ok in ('y', 'ye', 'yes'): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1267 |
return True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1268 |
if ok in ('n', 'no', 'nop', 'nope'): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1269 |
return False |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1270 |
retries = retries - 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1271 |
if retries < 0: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1272 |
raise IOError, 'bad user' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1273 |
print complaint |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1274 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1275 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1276 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1277 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1278 |
\frametitle{Functions: keyword arguments} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1279 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1280 |
def parrot(voltage, state='a stiff', |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1281 |
action='voom', type='Norwegian Blue'): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1282 |
print "-- This parrot wouldn't", action, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1283 |
print "if you put", voltage, "Volts through it." |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1284 |
print "-- Lovely plumage, the", type |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1285 |
print "-- It's", state, "!" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1286 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1287 |
parrot(1000) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1288 |
parrot(action = 'VOOOOOM', voltage = 1000000) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1289 |
parrot('a thousand', state = 'pushing up the daisies') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1290 |
parrot('a million', 'bereft of life', 'jump') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1291 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1292 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1293 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1294 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1295 |
\frametitle{Functions: arbitrary argument lists} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1296 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1297 |
\item Arbitrary number of arguments using \verb+*args+ or |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1298 |
\verb+*whatever+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1299 |
\item Keyword arguments using \verb+**kw+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1300 |
\item Given a tuple/dict how do you call a function? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1301 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1302 |
\item Using argument unpacking |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1303 |
\item For positional arguments: \verb+foo(*[5, 10])+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1304 |
\item For keyword args: \verb+foo(**{'a':5, 'b':10})+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1305 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1306 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1307 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1308 |
def foo(a=10, b=100): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1309 |
print a, b |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1310 |
def func(*args, **keyword): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1311 |
print args, keyword |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1312 |
# Unpacking: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1313 |
args = [5, 10] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1314 |
foo(*args) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1315 |
kw = {'a':5, 'b':10} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1316 |
foo(**kw) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1317 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1318 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1319 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1320 |
\subsection{Modules, exceptions, classes} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1321 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1322 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1323 |
\frametitle{Modules} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1324 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1325 |
\item Define variables, functions and classes in a file with a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1326 |
\typ{.py} extension |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1327 |
\item This file becomes a module! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1328 |
\item Modules are searched in the following: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1329 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1330 |
\item Current directory |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1331 |
\item Standard: \typ{/usr/lib/python2.3/site-packages/} etc. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1332 |
\item Directories specified in PYTHONPATH |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1333 |
\item \typ{sys.path}: current path settings (from the \typ{sys} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1334 |
module) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1335 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1336 |
\item The \typ{import} keyword ``loads'' a module |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1337 |
\item One can also use: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1338 |
\mbox{\typ{from module import name1, name2, name2}}\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1339 |
where \typ{name1} etc. are names in the module, ``module'' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1340 |
\item \typ{from module import *} \ --- imports everything from module, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1341 |
\alert{use only in interactive mode} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1342 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1343 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1344 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1345 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1346 |
\frametitle{Modules: example} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1347 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1348 |
# --- foo.py --- |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1349 |
some_var = 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1350 |
def fib(n): # write Fibonacci series up to n |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1351 |
"""Print a Fibonacci series up to n.""" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1352 |
a, b = 0, 1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1353 |
while b < n: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1354 |
print b, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1355 |
a, b = b, a+b |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1356 |
# EOF |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1357 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1358 |
>>> import foo |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1359 |
>>> foo.fib(10) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1360 |
1 1 2 3 5 8 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1361 |
>>> foo.some_var |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1362 |
1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1363 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1364 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1365 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1366 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1367 |
\frametitle{Namespaces} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1368 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1369 |
\item A mapping from names to objects |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1370 |
\item Modules introduce a namespace |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1371 |
\item So do classes |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1372 |
\item The running script's namespace is \verb+__main__+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1373 |
\item A modules namespace is identified by its name |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1374 |
\item The standard functions (like \typ{len}) are in the |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1375 |
\verb+__builtin__+ namespace |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1376 |
\item Namespaces help organize different names and their bindings to |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1377 |
different objects |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1378 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1379 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1380 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1381 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1382 |
\frametitle{Exceptions} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1383 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1384 |
\item Python's way of notifying you of errors |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1385 |
\item Several standard exceptions: \typ{SyntaxError}, \typ{IOError} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1386 |
etc. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1387 |
\item Users can also \typ{raise} errors |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1388 |
\item Users can create their own exceptions |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1389 |
\item Exceptions can be ``caught'' via \typ{try/except} blocks |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1390 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1391 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1392 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1393 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1394 |
\frametitle{Exception: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1395 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1396 |
>>> 10 * (1/0) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1397 |
Traceback (most recent call last): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1398 |
File "<stdin>", line 1, in ? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1399 |
ZeroDivisionError: integer division or modulo by zero |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1400 |
>>> 4 + spam*3 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1401 |
Traceback (most recent call last): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1402 |
File "<stdin>", line 1, in ? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1403 |
NameError: name 'spam' is not defined |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1404 |
>>> '2' + 2 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1405 |
Traceback (most recent call last): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1406 |
File "<stdin>", line 1, in ? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1407 |
TypeError: cannot concatenate 'str' and 'int' objects |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1408 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1409 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1410 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1411 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1412 |
\frametitle{Exception: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1413 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1414 |
>>> while True: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1415 |
... try: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1416 |
... x = int(raw_input("Enter a number: ")) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1417 |
... break |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1418 |
... except ValueError: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1419 |
... print "Invalid number, try again..." |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1420 |
... |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1421 |
>>> # To raise exceptions |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1422 |
... raise ValueError, "your error message" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1423 |
Traceback (most recent call last): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1424 |
File "<stdin>", line 2, in ? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1425 |
ValueError: your error message |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1426 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1427 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1428 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1429 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1430 |
\frametitle{Classes: the big picture} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1431 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1432 |
\item Lets you create new data types |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1433 |
\item Class is a template for an object belonging to that class |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1434 |
\item Note: in Python a class is also an object |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1435 |
\item Instantiating a class creates an instance (an object) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1436 |
\item An instance encapsulates the state (data) and behavior |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1437 |
(methods) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1438 |
\item Allows you to define an inheritance hierarchy |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1439 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1440 |
\item ``A Honda car \alert{is a} car.'' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1441 |
\item ``A car \alert{is an} automobile.'' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1442 |
\item ``A Python \alert{is a} reptile.'' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1443 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1444 |
\item Programmers need to think OO |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1445 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1446 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1447 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1448 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1449 |
\frametitle{Classes: what's the big deal?} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1450 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1451 |
\item Lets you create objects that mimic a real problem being |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1452 |
simulated |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1453 |
\item Makes problem solving more natural and elegant |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1454 |
\item Easier to create code |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1455 |
\item Allows for code-reuse |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1456 |
\item Polymorphism |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1457 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1458 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1459 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1460 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1461 |
\frametitle{Class definition and instantiation} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1462 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1463 |
\item Class definitions when executed create class objects |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1464 |
\item Instantiating the class object creates an instance of the |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1465 |
class |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1466 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1467 |
\footnotesize |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1468 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1469 |
class Foo(object): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1470 |
pass |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1471 |
# class object created. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1472 |
# Create an instance of Foo. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1473 |
f = Foo() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1474 |
# Can assign an attribute to the instance |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1475 |
f.a = 100 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1476 |
print f.a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1477 |
100 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1478 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1479 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1480 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1481 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1482 |
\frametitle{Classes \ldots} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1483 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1484 |
\item All attributes are accessed via the \typ{object.attribute} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1485 |
syntax |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1486 |
\item Both class and instance attributes are supported |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1487 |
\item \emph{Methods} represent the behavior of an object: crudely |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1488 |
think of them as functions ``belonging'' to the object |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1489 |
\item All methods in Python are ``virtual'' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1490 |
\item Inheritance through subclassing |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1491 |
\item Multiple inheritance is supported |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1492 |
\item No special public and private attributes: only good |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1493 |
conventions |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1494 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1495 |
\item \verb+object.public()+: public |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1496 |
\item \verb+object._private()+ \& \verb+object.__priv()+: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1497 |
non-public |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1498 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1499 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1500 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1501 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1502 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1503 |
\frametitle{Classes: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1504 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1505 |
class MyClass(object): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1506 |
"""Example class (this is the class docstring).""" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1507 |
i = 12345 # A class attribute |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1508 |
def f(self): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1509 |
"""This is the method docstring""" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1510 |
return 'hello world' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1511 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1512 |
>>> a = MyClass() # creates an instance |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1513 |
>>> a.f() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1514 |
'hello world' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1515 |
>>> # a.f() is equivalent to MyClass.f(a) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1516 |
... # This also explains why f has a 'self' argument. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1517 |
... MyClass.f(a) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1518 |
'hello world' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1519 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1520 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1521 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1522 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1523 |
\frametitle{Classes (continued)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1524 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1525 |
\item \typ{self} is \alert{conventionally} the first argument for a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1526 |
method |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1527 |
\item In previous example, \typ{a.f} is a method object |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1528 |
\item When \typ{a.f} is called, it is passed the instance \typ{a} as |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1529 |
the first argument |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1530 |
\item If a method called \verb+__init__+ exists, it is called when |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1531 |
the object is created |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1532 |
\item If a method called \verb+__del__+ exists, it is called before |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1533 |
the object is garbage collected |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1534 |
\item Instance attributes are set by simply ``setting'' them in |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1535 |
\typ{self} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1536 |
\item Other special methods (by convention) like \verb+__add__+ let |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1537 |
you define numeric types: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1538 |
{\footnotesize \url{http://docs.python.org/ref/specialnames.html} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1539 |
\\ \url{http://docs.python.org/ref/numeric-types.html} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1540 |
} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1541 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1542 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1543 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1544 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1545 |
\frametitle{Classes: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1546 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1547 |
class Bag(MyClass): # Shows how to derive classes |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1548 |
def __init__(self): # called on object creation. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1549 |
self.data = [] # an instance attribute |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1550 |
def add(self, x): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1551 |
self.data.append(x) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1552 |
def addtwice(self, x): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1553 |
self.add(x) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1554 |
self.add(x) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1555 |
>>> a = Bag() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1556 |
>>> a.f() # Inherited method |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1557 |
'hello world' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1558 |
>>> a.add(1); a.addtwice(2) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1559 |
>>> a.data |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1560 |
[1, 2, 2] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1561 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1562 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1563 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1564 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1565 |
\frametitle{Derived classes} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1566 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1567 |
\item Call the parent's \verb+__init__+ if needed |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1568 |
\item If you don't need a new constructor, no need to define it in subclass |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1569 |
\item Can also use the \verb+super+ built-in function |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1570 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1571 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1572 |
class AnotherBag(Bag): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1573 |
def __init__(self): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1574 |
# Must call parent's __init__ explicitly |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1575 |
Bag.__init__(self) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1576 |
# Alternatively use this: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1577 |
super(AnotherBag, self).__init__() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1578 |
# Now setup any more data. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1579 |
self.more_data = [] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1580 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1581 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1582 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1583 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1584 |
\frametitle{Classes: polymorphism} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1585 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1586 |
class Drawable(object): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1587 |
def draw(self): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1588 |
# Just a specification. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1589 |
pass |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1590 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1591 |
\mode<presentation>{\pause} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1592 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1593 |
class Square(Drawable): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1594 |
def draw(self): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1595 |
# draw a square. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1596 |
class Circle(Drawable): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1597 |
def draw(self): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1598 |
# draw a circle. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1599 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1600 |
\mode<presentation>{\pause} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1601 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1602 |
class Artist(Drawable): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1603 |
def draw(self): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1604 |
for obj in self.drawables: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1605 |
obj.draw() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1606 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1607 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1608 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1609 |
\subsection{Miscellaneous} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1610 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1611 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1612 |
\frametitle{Stand-alone scripts} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1613 |
Consider a file \typ{f.py}: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1614 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1615 |
#!/usr/bin/env python |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1616 |
"""Module level documentation.""" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1617 |
# First line tells the shell that it should use Python |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1618 |
# to interpret the code in the file. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1619 |
def f(): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1620 |
print "f" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1621 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1622 |
# Check if we are running standalone or as module. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1623 |
# When imported, __name__ will not be '__main__' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1624 |
if __name__ == '__main__': |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1625 |
# This is not executed when f.py is imported. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1626 |
f() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1627 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1628 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1629 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1630 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1631 |
\frametitle{List comprehensions} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1632 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1633 |
>>> veg = ['tomato', 'cabbage', 'carrot', 'potato'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1634 |
>>> [x.upper() for x in veg] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1635 |
['TOMATO', 'CABBAGE', 'CARROT', 'POTATO'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1636 |
>>> vec = range(0, 8) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1637 |
>>> even = [x for x in vec if x%2 == 0] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1638 |
>>> even |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1639 |
[0, 2, 4, 6] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1640 |
>>> [x*x for x in even] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1641 |
[0, 4, 16, 36] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1642 |
>>> odd = [x for x in vec if x%2 == 1] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1643 |
>>> odd |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1644 |
[1, 3, 5, 7] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1645 |
>>> [x*y for x in even for y in odd] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1646 |
[0, 0, 0, 0, 2, 6, 10, 14, 4, 12, 20, 28, 6, 18,30,42] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1647 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1648 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1649 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1650 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1651 |
\frametitle{More IPython features} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1652 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1653 |
\item Input and output caching: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1654 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1655 |
\item \verb+In+: a list of all entered input |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1656 |
\item \verb+Out+: a dict of all output |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1657 |
\item \verb+_+, \verb+__+, \verb+__+ are the last three results as |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1658 |
is \verb+_N+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1659 |
\item \verb+%hist [-n]+ macro shows previous history, \verb+-n+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1660 |
suppresses line number information |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1661 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1662 |
\item Log the session using \verb+%logstart+, \verb+%logon+ and |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1663 |
\verb+%logoff+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1664 |
\item \verb+%run [options] file[.py]+ -- running Python code |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1665 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1666 |
\item \verb+%run -d [-b<N>]+: debug script with pdb |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1667 |
\verb+N+ is the line number to break at (defaults to 1) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1668 |
\item \verb+%run -t+: time the script |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1669 |
\item \verb+%run -p+: Profile the script |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1670 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1671 |
\item \verb+%prun+ runs a statement/expression under the profiler |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1672 |
\item \verb+%macro [options] macro_name n1-n2 n3-n4 n6+ save specified |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1673 |
lines to a macro with name \verb+macro_name+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1674 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1675 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1676 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1677 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1678 |
\frametitle{More IPython features \ldots} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1679 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1680 |
\item \verb+%edit [options] [args]+: edit lines of code or file |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1681 |
specified in editor (configure editor via \verb+$EDITOR+) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1682 |
\item \verb+%cd+ changes directory, see also \verb+%pushd, %popd, %dhist+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1683 |
\item Shell access |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1684 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1685 |
\item \verb+!command+ runs a shell command and returns its output |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1686 |
\item \verb+files = %sx ls+ or \verb+files = !ls+ sets |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1687 |
\verb+files+ to all result of the \verb+ls+ command |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1688 |
\item \verb+%sx+ is quiet |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1689 |
\item \verb+!ls $files+ passes the \verb+files+ variable to the |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1690 |
shell command |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1691 |
\item \verb+%alias alias_name cmd+ creates an alias for a system |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1692 |
command |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1693 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1694 |
\item \verb+%colors+ lets you change the color scheme to |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1695 |
\verb+NoColor, Linux, LightBG+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1696 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1697 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1698 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1699 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1700 |
\frametitle{More IPython features \ldots} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1701 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1702 |
\item Use \verb+;+ at the end of a statement to suppress printing |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1703 |
output |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1704 |
\item \verb+%bookmark+: store a bookmarked location, for use with \verb+%cd+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1705 |
\item \verb+%who, %whos+: print information on variables |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1706 |
\item \verb+%save [options] filename n1-n2 n3-n4+: save lines to a |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1707 |
file |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1708 |
\item \verb+%time statement+: Time execution of a Python statement or |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1709 |
expression |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1710 |
\item \verb+%timeit [-n<N> -r<R> [-t|-c]] statement+: time execution |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1711 |
using Python's timeit module |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1712 |
\item Can define and use profiles to setup IPython differently: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1713 |
\verb+math, scipy, numeric, pysh+ etc. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1714 |
\item \verb+%magic+: \alert{Show help on all magics} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1715 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1716 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1717 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1718 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1719 |
\frametitle{File handling} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1720 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1721 |
>>> # Reading files: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1722 |
... f = open('/path/to/file_name') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1723 |
>>> data = f.read() # Read entire file. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1724 |
>>> line = f.readline() # Read one line. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1725 |
>>> # Read entire file appending each line into a list |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1726 |
... lines = f.readlines() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1727 |
>>> f.close() # close the file. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1728 |
>>> # Writing files: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1729 |
... f = open('/path/to/file_name', 'w') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1730 |
>>> f.write('hello world\n') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1731 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1732 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1733 |
\item \typ{tell()}: returns int of current position |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1734 |
\item \typ{seek(pos)}: moves current position to specified byte |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1735 |
\item Call \typ{close()} when done using a file |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1736 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1737 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1738 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1739 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1740 |
\frametitle{Math} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1741 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1742 |
\item \typ{math} module provides basic math routines for |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1743 |
floats |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1744 |
\item \typ{cmath} module provides math routies for complex |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1745 |
numbers |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1746 |
\item \typ{random}: provides pseudo-random number generators |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1747 |
for various distributions |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1748 |
\item These are always available and part of the standard library |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1749 |
\item More serious math is provided by the NumPy/SciPy modules -- |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1750 |
these are not standard and need to be installed separately |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1751 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1752 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1753 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1754 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1755 |
\frametitle{Timing and profiling} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1756 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1757 |
\item Timing code: use the \typ{time} module |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1758 |
\item Read up on \typ{time.time()} and \typ{time.clock()} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1759 |
\item \typ{timeit}: is a better way of doing timing |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1760 |
\item IPython has handy \typ{time} and \typ{timeit} macros (type |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1761 |
\typ{timeit?} for help) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1762 |
\item IPython lets you debug and profile code via the \typ{run} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1763 |
macro (type \typ{run?} on the prompt to learn more) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1764 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1765 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1766 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1767 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1768 |
\frametitle{Odds and ends} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1769 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1770 |
\item \typ{dir([object])} function: attributes of given object |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1771 |
\item \typ{type(object)}: returns type information |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1772 |
\item \typ{str(), repr()}: convert object to string representation |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1773 |
\item \typ{isinstance, issubclass} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1774 |
\item \typ{assert} statements let you do debugging assertions in |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1775 |
code |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1776 |
\item \typ{csv} module: reading and writing CSV files |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1777 |
\item \typ{pickle}: lets you save and load Python objects |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1778 |
(\alert{serialization}) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1779 |
\item \typ{sys.argv}: command line arguments |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1780 |
\item \typ{os.path}: common path manipulations |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1781 |
\item Check out the Python Library reference: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1782 |
\url{http://docs.python.org/lib/lib.html} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1783 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1784 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1785 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1786 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1787 |
\frametitle{Test driven development (TDD)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1788 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1789 |
\item Why? |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1790 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1791 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1792 |
\item Forces you to write reusable code! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1793 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1794 |
\item Think about the API |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1795 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1796 |
\item More robust |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1797 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1798 |
\item Makes refactoring very easy |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1799 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1800 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1801 |
\item How? Python offers three major ways of doing this |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1802 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1803 |
\item doctest |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1804 |
\item unittest |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1805 |
\item nosetest (and similar like py.test) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1806 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1807 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1808 |
\item Test every piece of functionality you offer |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1809 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1810 |
\item This isn't a formal introduction but more a practical one |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1811 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1812 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1813 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1814 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1815 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1816 |
\frametitle{Unit test} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1817 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1818 |
import unittest |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1819 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1820 |
class MyTestCase(unittest.TestCase): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1821 |
def setUp(self): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1822 |
# Called *before* each test_* |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1823 |
def tearDown(self): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1824 |
# Called *after* each test_* |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1825 |
def test_something(self): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1826 |
"docstring" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1827 |
# Test code. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1828 |
self.assertEqual(x, y) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1829 |
self.assertRaises(ValueError, func, arg1, arg2 ...) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1830 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1831 |
if __name__ == '__main__': |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1832 |
unittest.main() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1833 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1834 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1835 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1836 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1837 |
\frametitle{Nosetest} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1838 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1839 |
import particle |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1840 |
def test_particle(): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1841 |
# Use asserts here. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1842 |
p = particle.Particle(1.0) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1843 |
assert p.property[0] == 1.0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1844 |
assert p.property[2] == 0.0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1845 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1846 |
if __name__ == '__main__': |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1847 |
import nose |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1848 |
nose.main() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1849 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1850 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1851 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1852 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1853 |
\frametitle{Testing} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1854 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1855 |
\item More details: see library reference and search for nosetest |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1856 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1857 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1858 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1859 |
\section{Numerics \& Plotting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1860 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1861 |
\subsection{NumPy Arrays} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1862 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1863 |
\newcommand{\num}{\texttt{numpy}} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1864 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1865 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1866 |
\frametitle{The \num\ module} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1867 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1868 |
\item Manipulating large Python lists for scientific computing is |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1869 |
\alert{slow} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1870 |
\item Most complex computations can be reduced to a few standard |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1871 |
operations |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1872 |
\item The \num\ module provides: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1873 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1874 |
\item An efficient and powerful array type for various common data |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1875 |
types |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1876 |
\item Abstracts out the most commonly used standard operations on |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1877 |
arrays |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1878 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1879 |
\item Numeric was the first, then came \texttt{numarray}. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1880 |
\texttt{numpy} is the latest and is the future |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1881 |
\item This course uses \num\ and only covers the absolute basics |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1882 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1883 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1884 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1885 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1886 |
\frametitle{Basic concepts} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1887 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1888 |
\item \num\ arrays are of a fixed size (\typ{arr.size}) and have the |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1889 |
same type (\typ{arr.dtype}) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1890 |
\item \num\ arrays may have arbitrary dimensionality |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1891 |
\item The \typ{shape} of an array is the extent (length) of the |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1892 |
array along each dimension |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1893 |
\item The \typ{rank(arr)} of an array is the ``dimensionality'' of the |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1894 |
array |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1895 |
\item The \typ{arr.itemsize} is the number of bytes (8-bits) used for |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1896 |
each element of the array |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1897 |
\item \alert{Note:} The \typ{shape} and \typ{rank} may change as |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1898 |
long as the \typ{size} of the array is fixed |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1899 |
\item \alert{Note:} \typ{len(arr) != arr.size} in general |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1900 |
\item \alert{Note:} By default array operations are performed |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1901 |
\alert{elementwise} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1902 |
\item Indices start from 0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1903 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1904 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1905 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1906 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1907 |
\frametitle{Examples of \num} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1908 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1909 |
# Simple array math example |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1910 |
>>> from numpy import * |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1911 |
>>> a = array([1,2,3,4]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1912 |
>>> b = array([2,3,4,5]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1913 |
>>> a + b # Element wise addition! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1914 |
array([3, 5, 7, 9]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1915 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1916 |
>>> print pi, e # Pi and e are defined. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1917 |
3.14159265359 2.71828182846 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1918 |
# Create array from 0 to 10 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1919 |
>>> x = arange(0.0, 10.0, 0.05) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1920 |
>>> x *= 2*pi/10 # multiply array by scalar value |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1921 |
array([ 0.,0.0314,...,6.252]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1922 |
# apply functions to array. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1923 |
>>> y = sin(x) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1924 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1925 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1926 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1927 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1928 |
\frametitle{More examples of \num} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1929 |
\vspace*{-8pt} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1930 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1931 |
# Size, shape, rank, type etc. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1932 |
>>> x = array([1., 2, 3, 4]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1933 |
>>> size(x) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1934 |
4 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1935 |
>>> x.dtype # or x.dtype.char |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1936 |
'd' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1937 |
>>> x.shape |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1938 |
(4,) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1939 |
>>> print rank(x), x.itemsize |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1940 |
1 8 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1941 |
>>> x.tolist() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1942 |
[1.0, 2.0, 3.0, 4.0] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1943 |
# Array indexing |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1944 |
>>> x[0] = 10 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1945 |
>>> print x[0], x[-1] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1946 |
10.0 4.0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1947 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1948 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1949 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1950 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1951 |
\frametitle{Multi-dimensional arrays} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1952 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1953 |
>>> a = array([[ 0, 1, 2, 3], |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1954 |
... [10,11,12,13]]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1955 |
>>> a.shape # (rows, columns) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1956 |
(2, 4) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1957 |
# Accessing and setting values |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1958 |
>>> a[1,3] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1959 |
13 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1960 |
>>> a[1,3] = -1 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1961 |
>>> a[1] # The second row |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1962 |
array([10,11,12,-1]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1963 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1964 |
# Flatten/ravel arrays to 1D arrays |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1965 |
>>> a.flat # or ravel(a) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1966 |
array([0,1,2,3,10,11,12,-1]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1967 |
# Note: flat references original memory |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1968 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1969 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1970 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1971 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1972 |
\frametitle{Slicing arrays} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1973 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1974 |
>>> a = array([[1,2,3], [4,5,6], [7,8,9]]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1975 |
>>> a[0,1:3] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1976 |
array([2, 3]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1977 |
>>> a[1:,1:] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1978 |
array([[5, 6], |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1979 |
[8, 9]]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1980 |
>>> a[:,2] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1981 |
array([3, 6, 9]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1982 |
# Striding... |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1983 |
>>> a[0::2,0::2] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1984 |
array([[1, 3], |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1985 |
[7, 9]]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1986 |
# All these slices are references to the same memory! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1987 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1988 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1989 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1990 |
% \begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1991 |
% \frametitle{Array types and typecodes} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1992 |
% \begin{tabular}[c]{|c|c|p{2.75in}|} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1993 |
% \hline |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1994 |
% Character & Bits (bytes) & Type name \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1995 |
% \hline |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1996 |
% D & 128 (16) & \typ{Complex, Complex64}\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1997 |
% F & 64 (8) & \typ{Complex0, Complex8, Complex16} \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1998 |
% d & 64 (8) & \typ{Float, Float64} \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1999 |
% f & 32 (4) & \typ{Float0, Float8, Float16} \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2000 |
% i & 32 (4) & \typ{Int32} \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2001 |
% l & 32 (4) & \typ{Int} \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2002 |
% O & 4 (1) & \typ{PyObject} \\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2003 |
% %b 8 (1) UnsignedInt8 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2004 |
% %1 (one) 8 (1) Int8 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2005 |
% %s 16 (2) Int16 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2006 |
% \hline |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2007 |
% \end{tabular} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2008 |
% \begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2009 |
% # Examples |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2010 |
% >>> f = array([1,2,3], Float32) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2011 |
% >>> c = array([1,2,3], Complex32) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2012 |
% >>> print f, c |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2013 |
% [ 1. 2. 3.] [ 1.+0.j 2.+0.j 3.+0.j] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2014 |
% \end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2015 |
% \end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2016 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2017 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2018 |
\frametitle{Array creation functions} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2019 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2020 |
\item \typ{array(object, dtype=None, copy=1,order=None, subok=0,ndmin=0)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2021 |
\item \typ{arange(start, stop=None, step=1, dtype=None)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2022 |
\item \typ{linspace(start, stop, num=50, endpoint=True, retstep=False)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2023 |
\item \typ{ones(shape, dtype=None, order='C')} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2024 |
\item \typ{zeros((d1,...,dn),dtype=float,order='C')} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2025 |
\item \typ{identity(n)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2026 |
\item \typ{empty((d1,...,dn),dtype=float,order='C')} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2027 |
\item \typ{ones\_like(x)}, \typ{zeros\_like(x)}, \typ{empty\_like(x)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2028 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2029 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2030 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2031 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2032 |
\frametitle{Array math} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2033 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2034 |
\item Basic \alert{elementwise} math (given two arrays \typ{a, b}): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2035 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2036 |
\item \typ{a + b $\rightarrow$ add(a, b)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2037 |
\item \typ{a - b, $\rightarrow$ subtract(a, b)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2038 |
\item \typ{a * b, $\rightarrow$ multiply(a, b)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2039 |
\item \typ{a / b, $\rightarrow$ divide(a, b)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2040 |
\item \typ{a \% b, $\rightarrow$ remainder(a, b)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2041 |
\item \typ{a ** b, $\rightarrow$ power(a, b)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2042 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2043 |
\item Inplace operators: \typ{a += b}, or \typ{add(a, b, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2044 |
a)} etc. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2045 |
\item Logical operations: \typ{equal (==)}, \typ{not\_equal (!=)}, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2046 |
\typ{less (<)}, \typ{greater (>)} etc. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2047 |
\item Trig and other functions: \typ{sin(x), arcsin(x), sinh(x), |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2048 |
exp(x), sqrt(x)} etc. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2049 |
\item \typ{sum(x, axis=0), product(x, axis=0)}: sum and product of array elements |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2050 |
\item \typ{dot(a, b)} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2051 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2052 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2053 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2054 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2055 |
\frametitle{Advanced} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2056 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2057 |
\item Only scratched the surface of \num |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2058 |
\item Ufunc methods: \typ{reduce, accumulate, outer, reduceat} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2059 |
\item Typecasting |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2060 |
\item More functions: \typ{take, choose, where, compress, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2061 |
concatenate} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2062 |
\item Array broadcasting and \typ{None} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2063 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2064 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2065 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2066 |
\subsection{Plotting: Matplotlib} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2067 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2068 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2069 |
\frametitle{About \texttt{matplotlib}} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2070 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2071 |
\item Easy to use, scriptable, ``Matlab-like'' 2D plotting |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2072 |
\item Publication quality figures and interactive capabilities |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2073 |
\item Plots, histograms, power spectra, bar charts, errorcharts, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2074 |
scatterplots, etc. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2075 |
\item Also does polar plots, maps, contours |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2076 |
\item Support for simple \TeX\ markup |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2077 |
\item Multiple output backends (images, EPS, SVG, wx, Agg, Tk, GTK) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2078 |
\item Cross-platform: Linux, Win32, Mac OS X |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2079 |
\item Good idea to use via IPython: \typ{ipython -pylab} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2080 |
\item From scripts use: \typ{import pylab} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2081 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2082 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2083 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2084 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2085 |
\frametitle{More information} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2086 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2087 |
\item More information here: \url{http://matplotlib.sf.net} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2088 |
\item \url{http://matplotlib.sf.net/tutorial.html} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2089 |
\item \url{http://matplotlib.sf.net/screenshots.html} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2090 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2091 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2092 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2093 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2094 |
\frametitle{Basic plotting with \texttt{matplotlib}} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2095 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2096 |
>>> x = arange(0, 2*pi, 0.05) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2097 |
>>> plot(x, sin(x)) # Same as plot(x, sin(x), 'b-') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2098 |
>>> plot(x, sin(x), 'ro') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2099 |
>>> axis([0,2*pi, -1,1]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2100 |
>>> xlabel(r'$\chi$', color='g') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2101 |
>>> ylabel(r'sin($\chi$)', color='r') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2102 |
>>> title('A simple figure', fontsize=20) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2103 |
>>> savefig('/tmp/test.eps') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2104 |
# Multiple plots in one figure |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2105 |
>>> t = arange(0.0, 5.2, 0.2) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2106 |
# red dashes, blue squares and green triangles |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2107 |
>>> plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2108 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2109 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2110 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2111 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2112 |
\frametitle{Basic plotting \ldots} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2113 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2114 |
# Set properties of objects: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2115 |
>>> plot(x, sin(x), linewidth=2.0, color='r') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2116 |
>>> l, = plot(x, sin(x)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2117 |
>>> setp(l, linewidth=2.0, color='r') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2118 |
>>> l.set_linewidth(2.0); l.set_color('r') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2119 |
>>> draw() # Redraws current figure. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2120 |
>>> setp(l) # Prints available properties |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2121 |
>>> close() # Closes the figure. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2122 |
# Multiple figures: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2123 |
>>> figure(1); plot(x, sin(x)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2124 |
>>> figure(2); plot(x, tanh(x)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2125 |
>>> figure(1); title('Easy as 1,2,3') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2126 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2127 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2128 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2129 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2130 |
\frametitle{Basic plotting \ldots} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2131 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2132 |
>>> figure(1) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2133 |
>>> subplot(211) # Same as subplot(2, 1, 1) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2134 |
>>> plot(x, cos(5*x)*exp(-x)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2135 |
>>> subplot(2, 1, 2) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2136 |
>>> plot(x, cos(5*x), 'r--', label='cosine') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2137 |
>>> plot(x, sin(5*x), 'g--', label='sine') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2138 |
>>> legend() # Or legend(['cosine', 'sine']) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2139 |
>>> text(1,0, '(1,0)') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2140 |
>>> axes = gca() # Current axis |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2141 |
>>> fig = gcf() # Current figure |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2142 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2143 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2144 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2145 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2146 |
\frametitle{X-Y plot} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2147 |
\begin{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2148 |
\column{0.5\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2149 |
\hspace*{-0.5in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2150 |
\includegraphics[height=2in, interpolate=true]{data/xyplot} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2151 |
\column{0.45\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2152 |
\begin{block}{Example code} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2153 |
\tiny |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2154 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2155 |
t1 = arange(0.0, 5.0, 0.1) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2156 |
t2 = arange(0.0, 5.0, 0.02) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2157 |
t3 = arange(0.0, 2.0, 0.01) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2158 |
subplot(211) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2159 |
plot(t1, cos(2*pi*t1)*exp(-t1), 'bo', |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2160 |
t2, cos(2*pi*t2)*exp(-t2), 'k') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2161 |
grid(True) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2162 |
title('A tale of 2 subplots') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2163 |
ylabel('Damped') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2164 |
subplot(212) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2165 |
plot(t3, cos(2*pi*t3), 'r--') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2166 |
grid(True) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2167 |
xlabel('time (s)') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2168 |
ylabel('Undamped') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2169 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2170 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2171 |
\end{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2172 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2173 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2174 |
\begin{frame}[fragile] \frametitle{Errorbar} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2175 |
\begin{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2176 |
\column{0.5\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2177 |
\hspace*{-0.5in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2178 |
\includegraphics[height=2in, interpolate=true]{data/errorbar} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2179 |
\column{0.45\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2180 |
\begin{block}{Example code} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2181 |
\tiny |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2182 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2183 |
t = arange(0.1, 4, 0.1) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2184 |
s = exp(-t) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2185 |
e = 0.1*abs(randn(len(s))) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2186 |
f = 0.1*abs(randn(len(s))) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2187 |
g = 2*e |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2188 |
h = 2*f |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2189 |
errorbar(t, s, [e,g], f, fmt='o') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2190 |
xlabel('Distance (m)') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2191 |
ylabel('Height (m)') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2192 |
title('Mean and standard error '\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2193 |
'as a function of distance') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2194 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2195 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2196 |
\end{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2197 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2198 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2199 |
\begin{frame}[fragile] \frametitle{Semi-log and log-log plots} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2200 |
\begin{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2201 |
\column{0.5\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2202 |
\hspace*{-0.5in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2203 |
\includegraphics[height=2in, interpolate=true]{data/log} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2204 |
\column{0.45\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2205 |
\begin{block}{Example code} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2206 |
\tiny |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2207 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2208 |
dt = 0.01 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2209 |
t = arange(dt, 20.0, dt) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2210 |
subplot(311) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2211 |
semilogy(t, exp(-t/5.0)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2212 |
ylabel('semilogy') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2213 |
grid(True) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2214 |
subplot(312) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2215 |
semilogx(t, sin(2*pi*t)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2216 |
ylabel('semilogx') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2217 |
grid(True) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2218 |
# minor grid on too |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2219 |
gca().xaxis.grid(True, which='minor') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2220 |
subplot(313) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2221 |
loglog(t, 20*exp(-t/10.0), basex=4) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2222 |
grid(True) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2223 |
ylabel('loglog base 4 on x') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2224 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2225 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2226 |
\end{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2227 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2228 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2229 |
\begin{frame}[fragile] \frametitle{Histogram} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2230 |
\begin{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2231 |
\column{0.5\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2232 |
\hspace*{-0.5in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2233 |
\includegraphics[height=2in, interpolate=true]{data/histogram} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2234 |
\column{0.45\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2235 |
\begin{block}{Example code} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2236 |
\tiny |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2237 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2238 |
mu, sigma = 100, 15 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2239 |
x = mu + sigma*randn(10000) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2240 |
# the histogram of the data |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2241 |
n, bins, patches = hist(x, 100, normed=1) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2242 |
# add a 'best fit' line |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2243 |
y = normpdf( bins, mu, sigma) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2244 |
l = plot(bins, y, 'r--', linewidth=2) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2245 |
xlim(40, 160) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2246 |
xlabel('Smarts') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2247 |
ylabel('P') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2248 |
title(r'$\rm{IQ:}\/ \mu=100,\/ \sigma=15$') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2249 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2250 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2251 |
\end{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2252 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2253 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2254 |
\begin{frame}[fragile] \frametitle{Bar charts} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2255 |
\begin{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2256 |
\column{0.5\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2257 |
\hspace*{-0.5in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2258 |
\includegraphics[height=2in, interpolate=true]{data/barchart} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2259 |
\column{0.45\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2260 |
\begin{block}{Example code} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2261 |
\tiny |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2262 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2263 |
N = 5 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2264 |
menMeans = (20, 35, 30, 35, 27) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2265 |
menStd = ( 2, 3, 4, 1, 2) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2266 |
# the x locations for the groups |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2267 |
ind = arange(N) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2268 |
# the width of the bars |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2269 |
width = 0.35 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2270 |
p1 = bar(ind, menMeans, width, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2271 |
color='r', yerr=menStd) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2272 |
womenMeans = (25, 32, 34, 20, 25) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2273 |
womenStd = ( 3, 5, 2, 3, 3) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2274 |
p2 = bar(ind+width, womenMeans, width, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2275 |
color='y', yerr=womenStd) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2276 |
ylabel('Scores') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2277 |
title('Scores by group and gender') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2278 |
xticks(ind+width, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2279 |
('G1', 'G2', 'G3', 'G4', 'G5')) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2280 |
xlim(-width,len(ind)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2281 |
yticks(arange(0,41,10)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2282 |
legend((p1[0], p2[0]), |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2283 |
('Men', 'Women'), shadow=True) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2284 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2285 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2286 |
\end{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2287 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2288 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2289 |
\begin{frame}[fragile] \frametitle{Pie charts} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2290 |
\begin{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2291 |
\column{0.5\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2292 |
\hspace*{-0.4in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2293 |
\includegraphics[height=2.0in, interpolate=true]{data/piechart} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2294 |
\column{0.45\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2295 |
\begin{block}{Example code} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2296 |
\tiny |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2297 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2298 |
# make a square figure and axes |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2299 |
figure(1, figsize=(8,8)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2300 |
ax = axes([0.1, 0.1, 0.8, 0.8]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2301 |
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2302 |
fracs = [15,30,45, 10] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2303 |
explode=(0, 0.05, 0, 0) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2304 |
pie(fracs, explode=explode, labels=labels, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2305 |
autopct='%1.1f%%', shadow=True) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2306 |
title('Raining Hogs and Dogs', |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2307 |
bbox={'facecolor':'0.8', 'pad':5}) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2308 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2309 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2310 |
\end{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2311 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2312 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2313 |
\begin{frame}[fragile] \frametitle{Scatter plots} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2314 |
\begin{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2315 |
\column{0.5\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2316 |
\hspace*{-0.4in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2317 |
\includegraphics[height=2in, interpolate=true]{data/scatter} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2318 |
\column{0.45\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2319 |
\begin{block}{Example code} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2320 |
\tiny |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2321 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2322 |
N = 30 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2323 |
x = 0.9*rand(N) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2324 |
y = 0.9*rand(N) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2325 |
# 0 to 10 point radiuses |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2326 |
area = pi*(10 * rand(N))**2 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2327 |
volume = 400 + rand(N)*450 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2328 |
scatter(x,y,s=area, marker='o', c=volume, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2329 |
alpha=0.75) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2330 |
xlabel(r'$\Delta_i$', size='x-large') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2331 |
ylabel(r'$\Delta_{i+1}$', size='x-large') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2332 |
title(r'Volume and percent change') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2333 |
grid(True) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2334 |
colorbar() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2335 |
savefig('scatter') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2336 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2337 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2338 |
\end{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2339 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2340 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2341 |
\begin{frame}[fragile] \frametitle{Polar} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2342 |
\begin{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2343 |
\column{0.5\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2344 |
\hspace*{-0.5in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2345 |
\includegraphics[height=2in, interpolate=true]{data/polar} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2346 |
\column{0.45\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2347 |
\begin{block}{Example code} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2348 |
\tiny |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2349 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2350 |
figure(figsize=(8,8)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2351 |
ax = axes([0.1, 0.1, 0.8, 0.8], polar=True, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2352 |
axisbg='#d5de9c') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2353 |
r = arange(0,1,0.001) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2354 |
theta = 2*2*pi*r |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2355 |
polar(theta, r, color='#ee8d18', lw=3) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2356 |
# the radius of the grid labels |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2357 |
setp(ax.thetagridlabels, y=1.075) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2358 |
title(r"$\theta=4\pi r", fontsize=20) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2359 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2360 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2361 |
\end{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2362 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2363 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2364 |
\begin{frame}[fragile] \frametitle{Contours} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2365 |
\begin{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2366 |
\column{0.45\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2367 |
\hspace*{-0.5in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2368 |
\includegraphics[height=2in, interpolate=true]{data/contour} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2369 |
\column{0.525\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2370 |
\begin{block}{Example code} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2371 |
\tiny |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2372 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2373 |
x = arange(-3.0, 3.0, 0.025) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2374 |
y = arange(-2.0, 2.0, 0.025) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2375 |
X, Y = meshgrid(x, y) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2376 |
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2377 |
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2378 |
# difference of Gaussians |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2379 |
Z = 10.0 * (Z2 - Z1) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2380 |
im = imshow(Z, interpolation='bilinear', |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2381 |
origin='lower', |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2382 |
cmap=cm.gray, extent=(-3,3,-2,2)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2383 |
levels = arange(-1.2, 1.6, 0.2) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2384 |
# label every second level |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2385 |
clabel(CS, levels[1::2], inline=1, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2386 |
fmt='%1.1f', fontsize=14) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2387 |
CS = contour(Z, levels, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2388 |
origin='lower', |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2389 |
linewidths=2, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2390 |
extent=(-3,3,-2,2)) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2391 |
# make a colorbar for the contour lines |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2392 |
CB = colorbar(CS, shrink=0.8, extend='both') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2393 |
title('Lines with colorbar') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2394 |
hot(); flag() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2395 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2396 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2397 |
\end{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2398 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2399 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2400 |
\begin{frame}[fragile] \frametitle{Velocity vectors} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2401 |
\begin{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2402 |
\column{0.5\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2403 |
\hspace*{-0.5in} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2404 |
\includegraphics[height=2in, interpolate=true]{data/quiver} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2405 |
\column{0.45\textwidth} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2406 |
\begin{block}{Example code} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2407 |
\tiny |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2408 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2409 |
X,Y = meshgrid(arange(0,2*pi,.2), |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2410 |
arange(0,2*pi,.2) ) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2411 |
U = cos(X) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2412 |
V = sin(Y) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2413 |
Q = quiver(X[::3, ::3], Y[::3, ::3], |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2414 |
U[::3, ::3], V[::3, ::3], |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2415 |
color='r', units='x', |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2416 |
linewidths=(2,), |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2417 |
edgecolors=('k'), |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2418 |
headaxislength=5 ) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2419 |
qk = quiverkey(Q, 0.5, 0.03, 1, '1 m/s', |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2420 |
fontproperties= |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2421 |
{'weight': 'bold'}) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2422 |
axis([-1, 7, -1, 7]) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2423 |
title('triangular head; scale '\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2424 |
'with x view; black edges') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2425 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2426 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2427 |
\end{columns} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2428 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2429 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2430 |
\begin{frame}[fragile] \frametitle{Maps} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2431 |
\includegraphics[height=2.5in, interpolate=true]{data/plotmap} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2432 |
\begin{center} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2433 |
\tiny |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2434 |
For details see \url{http://matplotlib.sourceforge.net/screenshots/plotmap.py} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2435 |
\end{center} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2436 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2437 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2438 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2439 |
\subsection{SciPy} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2440 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2441 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2442 |
\frametitle{Using \texttt{SciPy}} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2443 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2444 |
\item SciPy is Open Source software for mathematics, science, and |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2445 |
engineering |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2446 |
\item \typ{import scipy} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2447 |
\item Built on NumPy |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2448 |
\item Provides modules for statistics, optimization, integration, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2449 |
linear algebra, Fourier transforms, signal and image processing, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2450 |
genetic algorithms, ODE solvers, special functions, and more |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2451 |
\item Used widely by scientists world over |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2452 |
\item Details are beyond the scope of this tutorial |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2453 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2454 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2455 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2456 |
\section{Standard library} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2457 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2458 |
\subsection{Quick Tour} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2459 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2460 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2461 |
\frametitle{Standard library} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2462 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2463 |
\item Very powerful |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2464 |
\item ``Batteries included'' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2465 |
\item Example standard modules taken from the tutorial |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2466 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2467 |
\item Operating system interface: \typ{os} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2468 |
\item System, Command line arguments: \typ{sys} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2469 |
\item Regular expressions: \typ{re} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2470 |
\item Math: \typ{math}, \typ{random} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2471 |
\item Internet access: \typ{urllib2}, \typ{smtplib} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2472 |
\item Data compression: \typ{zlib}, \typ{gzip}, \typ{bz2}, |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2473 |
\typ{zipfile}, and \typ{tarfile} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2474 |
\item Unit testing: \typ{doctest} and \typ{unittest} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2475 |
\item And a whole lot more! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2476 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2477 |
\item Check out the Python Library reference: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2478 |
\url{http://docs.python.org/lib/lib.html} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2479 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2480 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2481 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2482 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2483 |
\frametitle{Stdlib: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2484 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2485 |
>>> import os |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2486 |
>>> os.system('date') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2487 |
Fri Jun 10 22:13:09 IST 2005 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2488 |
0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2489 |
>>> os.getcwd() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2490 |
'/home/prabhu' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2491 |
>>> os.chdir('/tmp') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2492 |
>>> import os |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2493 |
>>> dir(os) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2494 |
<returns a list of all module functions> |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2495 |
>>> help(os) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2496 |
<extensive manual page from module's docstrings> |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2497 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2498 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2499 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2500 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2501 |
\frametitle{Stdlib: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2502 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2503 |
>>> import sys |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2504 |
>>> # Print the list of command line args to Python |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2505 |
... print sys.argv |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2506 |
[''] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2507 |
>>> import re # Regular expressions |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2508 |
>>> re.findall(r'\bf[a-z]*', |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2509 |
... 'which foot or hand fell fastest') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2510 |
['foot', 'fell', 'fastest'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2511 |
>>> re.sub(r'(\b[a-z]+) \1', r'\1', |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2512 |
... 'cat in the the hat') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2513 |
'cat in the hat' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2514 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2515 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2516 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2517 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2518 |
\frametitle{Stdlib: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2519 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2520 |
>>> import math |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2521 |
>>> math.cos(math.pi / 4.0) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2522 |
0.70710678118654757 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2523 |
>>> math.log(1024, 2) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2524 |
10.0 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2525 |
>>> import random |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2526 |
>>> random.choice(['apple', 'pear', 'banana']) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2527 |
'pear' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2528 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2529 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2530 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2531 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2532 |
\frametitle{Stdlib: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2533 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2534 |
>>> import urllib2 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2535 |
>>> f = urllib2.urlopen('http://www.python.org/') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2536 |
>>> print f.read(100) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2537 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2538 |
<?xml-stylesheet href="./css/ht2html |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2539 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2540 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2541 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2542 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2543 |
\frametitle{Stdlib: examples} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2544 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2545 |
>>> import zlib |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2546 |
>>> s = 'witch which has which witches wrist watch' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2547 |
>>> len(s) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2548 |
41 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2549 |
>>> t = zlib.compress(s) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2550 |
>>> len(t) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2551 |
37 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2552 |
>>> zlib.decompress(t) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2553 |
'witch which has which witches wrist watch' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2554 |
>>> zlib.crc32(t) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2555 |
-1438085031 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2556 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2557 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2558 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2559 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2560 |
\frametitle{Summary} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2561 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2562 |
\item Introduced Python |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2563 |
\item Basic syntax |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2564 |
\item Basic types and data structures |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2565 |
\item Control flow |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2566 |
\item Functions |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2567 |
\item Modules |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2568 |
\item Exceptions |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2569 |
\item Classes |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2570 |
\item Standard library |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2571 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2572 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2573 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2574 |
\end{document} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2575 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2576 |
\subsection{Basic data structures} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2577 |
\begin{frame}{Lists} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2578 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2579 |
\item \texttt{species = [ 'humans', 'orcs', 'elves', 'dwarves' ]} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2580 |
\item \texttt{ ids = [ 107, 109, 124, 141, 142, 144 ]} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2581 |
\item \texttt{ oneliners = [ 'I will be back', 'Do or do not! No try!!', 42 ] } |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2582 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2583 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2584 |
\begin{block}{List operations} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2585 |
ids + [ 100, 102 ]\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2586 |
species.append( 'unicorns')\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2587 |
print oneliners[ 1 ]\\ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2588 |
look up \alert{docs.python.org/tutorial/datastructures.html} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2589 |
\end{block} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2590 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2591 |
\end{document} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2592 |
\section{Python Tutorial} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2593 |
\subsection{Preliminaries} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2594 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2595 |
\frametitle{Using the interpreter} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2596 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2597 |
\item Starting up: \typ{python} or \typ{ipython} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2598 |
\item Quitting: \typ{Control-D} or \typ{Control-Z} (on Win32) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2599 |
\item Can use it like a calculator |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2600 |
\item Can execute one-liners via the \typ{-c} option: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2601 |
\typ{python -c "print 'hello world'"} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2602 |
\item Other options via \typ{python -h} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2603 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2604 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2605 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2606 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2607 |
\frametitle{IPython} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2608 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2609 |
\item Recommended interpreter, IPython: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2610 |
\url{http://ipython.scipy.org} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2611 |
\item Better than the default Python shell |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2612 |
\item Supports tab completion by default |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2613 |
\item Easier object introspection |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2614 |
\item Shell access! |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2615 |
\item Command system to allow extending its own behavior |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2616 |
\item Supports history (across sessions) and logging |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2617 |
\item Can be embedded in your own Python code |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2618 |
\item Support for macros |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2619 |
\item A flexible framework for your own custom interpreter |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2620 |
\item Other miscellaneous conveniences |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2621 |
\item We'll get back to this later |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2622 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2623 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2624 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2625 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2626 |
\frametitle{Basic IPython features} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2627 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2628 |
\item Startup: \verb+ipython [options] files+ |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2629 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2630 |
\item \verb+ipython [-wthread|-gthread|-qthread]+: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2631 |
Threading modes to support wxPython, pyGTK and Qt |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2632 |
\item \verb+ipython -pylab+: Support for matplotlib |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2633 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2634 |
\item TAB completion: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2635 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2636 |
\item Type \verb+object_name.<TAB>+ to see list of options |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2637 |
\item Also completes on file and directory names |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2638 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2639 |
\item \verb+object?+ shows docstring/help for any Python object |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2640 |
\item \verb+object??+ presents more docs (and source if possible) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2641 |
\item Debugging with \verb+%pdb+ magic: pops up pdb on errors |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2642 |
\item Access history (saved over earlier sessions also) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2643 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2644 |
\item Use \texttt{<UpArrow>}: move up history |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2645 |
\item Use \texttt{<Ctrl-r> string}: search history backwards |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2646 |
\item Use \texttt{Esc >}: get back to end of history |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2647 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2648 |
\item \verb+%run [options] file[.py]+ lets you run Python code |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2649 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2650 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2651 |
% LocalWords: BDFL Guido Rossum PSF Nokia OO Zope CMS RedHat SciPy MayaVi spam |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2652 |
% LocalWords: IPython ipython stdin TypeError dict int elif PYTHONPATH IOError |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2653 |
% LocalWords: namespace Namespaces SyntaxError ZeroDivisionError NameError str |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2654 |
% LocalWords: ValueError subclassed def |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2655 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2656 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2657 |
\item Types are of two kinds: \alert{mutable} and \alert{immutable} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2658 |
\item Immutable types: numbers, strings, \typ{None} and tuples |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2659 |
\item Immutables cannot be changed ``in-place'' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2660 |
\item Mutable types: lists, dictionaries, instances, etc. |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2661 |
\item Mutable objects can be ``changed'' |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2662 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2663 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2664 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2665 |
\begin{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2666 |
\frametitle{Important!} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2667 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2668 |
\item Assignment to an object is by reference |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2669 |
\item Essentially, \alert{names are bound to objects} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2670 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2671 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2672 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2673 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2674 |
\end{document} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2675 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2676 |
\frametitle{Dictionaries} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2677 |
\begin{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2678 |
\item Associative arrays/mappings |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2679 |
\item Indexed by ``keys'' (keys must be immutable) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2680 |
\item \typ{dict[key] = value} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2681 |
\item \typ{keys()} returns all keys of the dict |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2682 |
\item \typ{values()} returns the values of the dict |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2683 |
\item \verb+has_key(key)+ returns if \typ{key} is in the dict |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2684 |
\end{itemize} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2685 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2686 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2687 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2688 |
\frametitle{Dictionaries: example} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2689 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2690 |
>>> tel = {'jack': 4098, 'sape': 4139} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2691 |
>>> tel['guido'] = 4127 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2692 |
>>> tel |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2693 |
{'sape': 4139, 'guido': 4127, 'jack': 4098} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2694 |
>>> tel['jack'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2695 |
4098 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2696 |
>>> del tel['sape'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2697 |
>>> tel['irv'] = 4127 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2698 |
>>> tel |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2699 |
{'guido': 4127, 'irv': 4127, 'jack': 4098} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2700 |
>>> tel.keys() |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2701 |
['guido', 'irv', 'jack'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2702 |
>>> tel.has_key('guido') |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2703 |
True |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2704 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2705 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2706 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2707 |
\subsection{Control flow, functions} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2708 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2709 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2710 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2711 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2712 |
\frametitle{\typ{If} example} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2713 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2714 |
>>> a = ['cat', 'window', 'defenestrate'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2715 |
>>> if 'cat' in a: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2716 |
... print "meaw" |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2717 |
... |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2718 |
meaw |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2719 |
>>> pets = {'cat': 1, 'dog':2, 'croc': 10} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2720 |
>>> if 'croc' in pets: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2721 |
... print pets['croc'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2722 |
... |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2723 |
10 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2724 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2725 |
\end{frame} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2726 |
|
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2727 |
\begin{frame}[fragile] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2728 |
\frametitle{\typ{for} example} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2729 |
\begin{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2730 |
>>> a = ['cat', 'window', 'defenestrate'] |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2731 |
>>> for x in a: |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2732 |
... print x, len(x) |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2733 |
... |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2734 |
cat 3 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2735 |
window 6 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2736 |
defenestrate 12 |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2737 |
>>> knights = {'gallahad': 'the pure', |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2738 |
... 'robin': 'the brave'} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2739 |
>>> for k, v in knights.iteritems(): |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2740 |
... print k, v |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2741 |
... |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2742 |
gallahad the pure |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2743 |
robin the brave |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2744 |
\end{lstlisting} |
838cedef5e9d
Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2745 |
\end{frame} |