Merged Vattam and Puneeth branches.
Binary file day1/data/fsolve_tanx.png has changed
Binary file day1/data/science_nolabel.png has changed
Binary file day1/data/triangle.png has changed
--- a/day1/day1quiz1.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/day1quiz1.tex Fri Apr 02 15:45:07 2010 +0530
@@ -55,27 +55,29 @@
\item Name:
\item University/College/Company:
\item Student/Teacher/Professional:
+ \item Field of interest/study:
\end{itemize}
\end{frame}
-\begin{frame}[fragile]
-\frametitle{\incqno }
-Draw (roughly) the plot obtained by the following:
-\begin{lstlisting}
-In []: x = linspace(0, 2*pi, 3)
-In []: plot(x, sin(x))
-\end{lstlisting}
-\end{frame}
-
%% \begin{frame}[fragile]
%% \frametitle{\incqno }
-%% Describe the plot produced by the following:
+%% Draw (roughly) the plot obtained by the following:
%% \begin{lstlisting}
-%% In []: x = linspace(0, 2*pi, 50)
-%% In []: plot(x, cos(x), 'go')
+%% In []: x = linspace(0, 2*pi, 3)
+%% In []: plot(x, sin(x))
%% \end{lstlisting}
%% \end{frame}
+\begin{frame}[fragile]
+\frametitle{\incqno }
+Describe the plot produced by the following:
+\begin{lstlisting}
+In []: x = linspace(0, 2*pi, 50)
+In []: plot(x, cos(x), 'go')
+\end{lstlisting}
+Note: Do not draw it, just describe the plot
+\end{frame}
+
\begin{frame}
\frametitle{\incqno }
How will you plot the previous graph with line width set to 3? How will
@@ -94,18 +96,18 @@
What ipython magic command do you use to obtain the lines of code you have already typed in the interpreter? What command do you use to save them?
\end{frame}
-\begin{frame}[fragile]
-\frametitle{\incqno }
-The following code snippet has an error/bug:
-\begin{lstlisting}
-In []: y = linspace(0, 2*pi, 50)
-In []: plot(y, sin(y))
-In []: clf()
-In []: plot(y, cos(y))
-In []: legend(['sin(y)', 'cos(y)'])
-\end{lstlisting}
-What is the error? How do you fix it?
-\end{frame}
+%% \begin{frame}[fragile]
+%% \frametitle{\incqno }
+%% The following code snippet has an error/bug:
+%% \begin{lstlisting}
+%% In []: y = linspace(0, 2*pi, 50)
+%% In []: plot(y, sin(y))
+%% In []: clf()
+%% In []: plot(y, cos(y))
+%% In []: legend(['sin(y)', 'cos(y)'])
+%% \end{lstlisting}
+%% What is the error? How do you fix it?
+%% \end{frame}
\begin{frame}[fragile]
\frametitle{\incqno }
@@ -134,15 +136,15 @@
Write the code to read a file \texttt{data.txt} and print each line of it?
\end{frame}
-\begin{frame}[fragile]
-\frametitle{\incqno }
-What would be the result of the following code snippet:
-\begin{lstlisting}
-In []: x = linspace(0, 10, 50)
-In []: y = linspace(50, 100, 100)
-In []: plot(x, y)
-\end{lstlisting}
-\end{frame}
+%% \begin{frame}[fragile]
+%% \frametitle{\incqno }
+%% What would be the result of the following code snippet:
+%% \begin{lstlisting}
+%% In []: x = linspace(0, 10, 50)
+%% In []: y = linspace(50, 100, 100)
+%% In []: plot(x, y)
+%% \end{lstlisting}
+%% \end{frame}
\begin{frame}[fragile]
\frametitle{\incqno }
@@ -203,17 +205,17 @@
In []: marks = [10, 20, 30, 50, 55,
75, 83]
\end{lstlisting}
-Given the above marks, how will you calculate the \alert{mean} and
-\alert{standard deviation}?
+Given the above marks, how will you calculate the \alert{mean}?%% and
+%% \alert{standard deviation}?
\end{frame}
-\begin{frame}[fragile]
-\frametitle{\incqno }
-\begin{lstlisting}
-In []: marks = [10, 20, 30, 50, 55,
- 75, 83]
-\end{lstlisting}
-How will you convert the list \texttt{marks} to an \alert{array}?
-\end{frame}
+%% \begin{frame}[fragile]
+%% \frametitle{\incqno }
+%% \begin{lstlisting}
+%% In []: marks = [10, 20, 30, 50, 55,
+%% 75, 83]
+%% \end{lstlisting}
+%% How will you convert the list \texttt{marks} to an \alert{array}?
+%% \end{frame}
\end{document}
--- a/day1/day1quiz2.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/day1quiz2.tex Fri Apr 02 15:45:07 2010 +0530
@@ -35,7 +35,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Title page
-\title[Basic Python]{Python for science and engineering: Day 1, Quiz 2}
+\title[Basic Python]{Python for science and engineering: Day 2, Quiz 1}
\author[FOSSEE Team] {FOSSEE}
@@ -58,6 +58,7 @@
\item Name:
\item University/College/Company:
\item Student/Teacher/Professional:
+ \item Field of interest/study:
\end{itemize}
\end{frame}
@@ -170,10 +171,10 @@
\texttt{Ax = b}?
\end{frame}
-\begin{frame}
-\frametitle{\incqno }
-What command will you use if you wish to integrate a system of ODEs?
-\end{frame}
+%% \begin{frame}
+%% \frametitle{\incqno }
+%% What command will you use if you wish to integrate a system of ODEs?
+%% \end{frame}
\begin{frame}
\frametitle{\incqno }
--- a/day1/exercise/aliquot.py Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/exercise/aliquot.py Fri Apr 02 15:45:07 2010 +0530
@@ -1,5 +1,7 @@
-
def aliquot(n):
+ """returns the aliquot of a number which
+ is defined as the sum of all the proper
+ divisors of a number"""
sum = 1
i = 2
@@ -7,7 +9,7 @@
if n % i == 0:
sum += i + (n / i)
i += 1
- if n % i == 0: sum += i
+ if i*i == n: sum += i
return sum
n = int(raw_input('Enter a number? '))
--- a/day1/exercise/amicable.py Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/exercise/amicable.py Fri Apr 02 15:45:07 2010 +0530
@@ -1,15 +1,8 @@
-def is_perfect_square(n):
- i = 1
- while i * i < n:
- i += 1
- return i * i == n, i
-
def aliquot(n):
sum = 1
i = 2
- is_ps, root = is_perfect_square(n)
- while i < root:
+ while i * i < n:
if n % i == 0:
sum += i + (n / i)
i += 1
--- a/day1/exercise/amicable_debug.py Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/exercise/amicable_debug.py Fri Apr 02 15:45:07 2010 +0530
@@ -1,16 +1,20 @@
import math
def aliquot(n):
- sum = 0
- for i in range(1, math.sqrt(n)+1):
+ sum = 1
+ i = 2
+
+ while i * i < n:
if n % i == 0:
- sum += i + n/i
+ sum += i + (n / i)
+ i += 1
+ if i*i == n: sum += i
return sum
amicable = []
-for n in range(10000, 100000):
+for n in range(1000, 10000):
m = aliquot(n)
- if aliquot(m) == n:
+ if m > n and aliquot(m) == n:
amicable.append((m, n))
print amicable
--- a/day1/exercise/even_perfect_4a.py Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/exercise/even_perfect_4a.py Fri Apr 02 15:45:07 2010 +0530
@@ -11,4 +11,4 @@
square = i * i
if all_digits_even(square):
print square
- i += 1
+ i += 2
--- a/day1/exercise/kwfreq.py Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/exercise/kwfreq.py Fri Apr 02 15:45:07 2010 +0530
@@ -1,6 +1,3 @@
-import keyword
-f = open('amicable.py')
-
freq = {}
for line in f:
words = line.split()
--- a/day1/exercise/pytriads.py Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/exercise/pytriads.py Fri Apr 02 15:45:07 2010 +0530
@@ -10,8 +10,8 @@
else:
return gcd(b, a%b)
-for a in range(3, 501):
- for b in range( a+1, 501, 2):
+for a in range(3, 101):
+ for b in range( a+1, 101, 2):
if gcd( a, b ) == 1:
is_ps, c = is_perfect_square((a * a) + (b * b))
if is_ps: print a, b, c
--- a/day1/exercise/word_frequencies.py Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/exercise/word_frequencies.py Fri Apr 02 15:45:07 2010 +0530
@@ -1,11 +1,13 @@
-f = open('/home/madhu/pyprogs/pytriads.py')
+f = open('/home/vattam/Desktop/circulate/word-freq/holmes.txt')
freq = {}
for line in f:
words = line.split()
for word in words:
key = word.strip(',.!;?\'" ')
- value = freq.get(key, 1)
- freq[key] = value + 1
+ if key in freq:
+ freq[key] += 1
+ else:
+ freq[key] = 1
print freq
--- a/day1/session1.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/session1.tex Fri Apr 02 15:45:07 2010 +0530
@@ -77,7 +77,7 @@
\author[FOSSEE] {FOSSEE}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {28 January, 2010\\Day 1, Session 1}
+\date[] {02 April, 2010\\Day 1, Session 1}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
@@ -123,6 +123,60 @@
%% \end{frame}
\begin{frame}
+ \frametitle{Workshop Schedule: Day 1}
+ \begin{description}
+ \item[Session 1] Mon 09:00--10:00
+ \item[Session 2] Mon 10:05--11:05
+ \item[Session 3] Mon 11:20--12:20
+ \item[Session 4] Mon 12:25--13:25
+ \item[Quiz 1] Mon 14:25--14:45
+ \item[Exercises] Mon 14:45--15:30
+ \item[Session 5] Mon 15:45--16:45
+ \item[Quiz 2] Mon 16:50--17:05
+ \end{description}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Workshop Schedule: Day 2}
+ \begin{description}
+ \item[Session 1] Tue 09:00--10:00
+ \item[Session 2] Tue 10:05--11:05
+ \item[Session 3] Tue 11:20--12:20
+ \item[Session 4] Tue 12:25--13:25
+ \item[Quiz 1] Tue 14:25--14:45
+ \item[Exercises] Tue 14:45--15:30
+ \item[Session 5] Tue 15:45--16:45
+ \end{description}
+\end{frame}
+
+\section{Checklist}
+\begin{frame}
+\frametitle{Checklist}
+ \begin{enumerate}
+ \item IPython
+ \item Editor - we recommend \alert{scite}
+ \item Data files:
+ \begin{itemize}
+ \item \typ{sslc1.txt}
+ \item \typ{pendulum.txt}
+ \item \typ{pos.txt}
+ \item \typ{holmes.txt}
+ \item \typ{anag.txt}
+ \end{itemize}
+ \item Python scripts:
+ \begin{itemize}
+ \item \typ{sslc_allreg.py}
+ \item \typ{sslc_science.py}
+ \end{itemize}
+ \item Images
+ \begin{itemize}
+ \item \typ{lena.png}
+ \item \typ{smoothing.gif}
+ \end{itemize}
+ \end{enumerate}
+\end{frame}
+
+\begin{frame}
\frametitle{About the Workshop}
\begin{block}{Intended Audience}
\begin{itemize}
@@ -140,6 +194,73 @@
\end{block}
\end{frame}
+\begin{frame}[fragile]
+\frametitle{The Python interpreter \ldots}
+\begin{block}{}
+\begin{lstlisting}
+ $ python
+\end{lstlisting} %$
+\end{block}
+\begin{lstlisting}
+ >>> print "Hello, World!"
+ Hello, World!
+\end{lstlisting}
+Exiting
+\begin{lstlisting}
+ >>> ^D(Ctrl-D)
+ $
+\end{lstlisting} %$
+\end{frame}
+
+\section{Starting up Ipython}
+\begin{frame}[fragile]
+\frametitle{Starting up \ldots}
+\begin{block}{}
+\begin{lstlisting}
+ $ ipython
+\end{lstlisting} %$
+\end{block}
+\begin{lstlisting}
+ In []: print "Hello, World!"
+ Hello, World!
+\end{lstlisting}
+Exiting
+\begin{lstlisting}
+ In []: ^D(Ctrl-D)
+ Do you really want to exit([y]/n)? y
+\end{lstlisting}
+An alternative to IPython is bpython
+\end{frame}
+
+\section{Ipython with magic}
+\begin{frame}[fragile]
+\frametitle{Let the magic begin \ldots}
+\begin{itemize}
+\item \alert{IPython is an improved interpreter}\\
+\item \alert{Recommended for Scientific and Computing work}\\
+\end{itemize}
+\begin{block}{}
+\begin{lstlisting}
+ $ ipython -pylab
+\end{lstlisting} %$
+\end{block}
+\end{frame}
+
+\section{Loops}
+\begin{frame}[fragile]
+\frametitle{Loops}
+Breaking out of loops
+\begin{lstlisting}
+ In []: while True:
+ ...: print "Hello, World!"
+ ...:
+ Hello, World!
+ Hello, World!^C(Ctrl-C)
+ ------------------------------------
+ KeyboardInterrupt
+\end{lstlisting}
+\end{frame}
+
\section{Plotting}
\subsection{Drawing plots}
\begin{frame}[fragile]
@@ -277,6 +398,17 @@
In []: close()
\end{lstlisting}
+Supported formats to store images:
+\begin{itemize}
+\item png
+\item eps - Easy to embed in LaTeX files
+\item emf
+\item pdf
+\item ps
+\item raw
+\item rgba
+\item svg
+\end{itemize}
\end{frame}
\section{Multiple plots}
@@ -301,8 +433,10 @@
In []: plot(y, sin(y))
In []: figure(2)
In []: plot(y, cos(y))
+In []: savefig('cosine.png')
In []: figure(1)
In []: title('sin(y)')
+In []: savefig('sine.png')
In []: close()
In []: close()
\end{lstlisting}
@@ -312,10 +446,10 @@
\frametitle{Showing it better}
\vspace{-0.15in}
\begin{lstlisting}
-In []: plot(y, sin(y), 'g')
+In []: plot(y, cos(y), 'r')
In []: clf()
-In []: plot(y, cos(y), 'r', linewidth=2)
+In []: plot(y, sin(y), 'g', linewidth=2)
\end{lstlisting}
\vspace*{-0.2in}
\begin{center}
@@ -338,16 +472,15 @@
\begin{frame}[fragile]
\frametitle{Axes lengths}
-\emphbar{Get the axes limits}
+\emphbar{Getting axes lengths}
\begin{lstlisting}
In []: xmin, xmax = xlim()
In []: ymin, ymax = ylim()
\end{lstlisting}
\emphbar{Set the axes limits}
\begin{lstlisting}
-In []: xmax = 2*pi
-In []: xlim(xmin, xmax)
-In []: ylim(ymin-0.2, ymax+0.2)
+In []: xlim(xmin, 2*pi )
+In []: ylim(ymin-0.2, ymax+0.2)
\end{lstlisting}
\end{frame}
@@ -395,37 +528,55 @@
\end{frame}
\begin{frame}[fragile]
-\frametitle{Saving Commands}
-Save commands of review problem into file
-\begin{itemize}
-\item Use \typ{\%hist} command of IPython (Recall \%\typ{hist} from the previous session)
-\item Identify the required line numbers
-\item Then, use \typ{\%save} command of IPython (Recall \%\typ{save} from the previous session)
-\end{itemize}
+\frametitle{Command History}
+Use the \typ{\%hist} \alert{magic} command of IPython
\typ{In []: \%hist}\\
-\typ{In []: \%save four_plot.py} \alert{\typ{16 18-27}}
+This displays all the commands typed in so far aka Command History.
\begin{block}{Careful about errors!}
- \kwrd{\%hist} will contain the errors as well,\\
- so be careful while selecting line numbers.
+ \kwrd{\%hist} will contain the errors as well.\\
+\end{block}
+\begin{block}{Magic Commands?}
+ Magic commands are commands provided by IPython to make our life easier.
\end{block}
\end{frame}
+\begin{frame}[fragile]
+ \frametitle{Saving commands into script}
+Use the \typ{\%save} \alert{magic} command of IPython
+\begin{block}{}
+\typ{\%save script_name line_numbers}
+\end{block}
+Line numbers can be specified individually separated by commas or as a range separated by a dash.\\
+\begin{block}{}
+\typ{\%save four_plot.py} \alert{\typ{16 18-27}} \\
+\end{block}
+This saves from the history the commands entered on line numbers \alert{16, 18, 19, 20, \ldots 27}
+\end{frame}
+
\begin{frame}
\frametitle{Python Scripts\ldots}
- This is called a Python Script.
+Now, four\_plot.py is called a Python Script.
\begin{itemize}
- \item run the script in IPython using \typ{\%run -i four_plot.py}\\
+ \item run the script in IPython using \typ{\%run four_plot.py}\\
\end{itemize}
+\pause
+\alert{\typ{NameError: name 'linspace' is not defined}}
+\begin{block}{}
+To avoid this, run using \alert{\typ{\%run -i four_plot.py}}\\
+\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{What did we learn?}
\begin{itemize}
- \item Running a script using \kwrd{\%run -i}
+ \item Starting up IPython
\item Creating simple plots.
\item Adding labels and legends.
\item Annotating plots.
\item Changing the looks: size, linewidth
+ \item \kwrd{\%hist} - History of commands
+ \item \kwrd{\%save} - Saving commands
+ \item Running a script using \kwrd{\%run -i}
\end{itemize}
\end{frame}
--- a/day1/session2.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/session2.tex Fri Apr 02 15:45:07 2010 +0530
@@ -78,7 +78,7 @@
\author[FOSSEE] {FOSSEE}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {28 January, 2010\\Day 1, Session 2}
+\date[] {02 April, 2010\\Day 1, Session 2}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
@@ -208,43 +208,48 @@
\end{lstlisting}
\emphbar{Empty List}
\begin{lstlisting}
-In []: a = [ 1, 2, 3, 4, 5]
+In []: p = [ 2, 3, 5, 7]
-In []: a[0]+a[1]+a[-1]
-Out[]: 8
+In []: p[1]
+Out[]: 3
+
+In []: p[0]+p[1]+p[-1]
+Out[]: 12
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{List: Slicing}
\begin{block}{Remember\ldots}
- \kwrd{In []: a = [ 1, 2, 3, 4, 5]}
+ \kwrd{In []: p = [ 2, 3, 5, 7]}
\end{block}
\begin{lstlisting}
-In []: a[1:3]
-Out[]: [2, 3]
+In []: p[1:3]
+Out[]: [3, 5]
\end{lstlisting}
\emphbar{A slice}
\begin{lstlisting}
-In []: a[1:-1]
-Out[]: [2, 3, 4]
+In []: p[0:-1]
+Out[]: [2, 3, 5]
+In []: p[::2]
+Out[]: [2, 5]
\end{lstlisting}
-\alert{\typ{list[initial:final]}}
+\alert{\typ{list[initial:final:step]}}
\end{frame}
%% more on list slicing
\begin{frame}[fragile]
\frametitle{List operations}
\begin{lstlisting}
-In []: b = [ 6, 7, 8, 9]
-In []: c = a + b
+In []: b = [ 11, 13, 17]
+In []: c = p + b
In []: c
-Out[]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
+Out[]: [2, 3, 5, 7, 11, 13, 17]
-In []: a.append(6)
-In []: a
-Out[]: [ 1, 2, 3, 4, 5, 6]
+In []: p.append(11)
+In []: p
+Out[]: [ 2, 3, 5, 7, 11]
\end{lstlisting}
%\inctime{10}
\end{frame}
@@ -276,7 +281,7 @@
\begin{frame}[fragile]
\frametitle{Lets use lists}
\begin{lstlisting}
-In []: l = [0.1, 0.2, 0.3, 0.4, 0.5,
+In []: L = [0.1, 0.2, 0.3, 0.4, 0.5,
0.6, 0.7, 0.8, 0.9]
In []: t = [0.69, 0.90, 1.19,
@@ -304,22 +309,24 @@
....:
....:
-In []: plot(l, tsq)
-Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>]
\end{lstlisting}
This gives \kwrd{tsq} which is the list of squares of \typ{t} values.
+\begin{lstlisting}
+In []: print len(L), len(t), len(tsq)
+Out[]: 9 9 9
+\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{How to come out of the \texttt{for} loop?}
- Recall that hitting the ``ENTER'' key twice returns the cursor to the previous indentation level
+ Hitting the ``ENTER'' key twice returns the cursor to the previous indentation level
\begin{lstlisting}
In []: for time in t:
....: tsq.append(time*time)
....:
....:
- In []: print tsq
+ In []: plot(L, tsq)
\end{lstlisting}
\end{frame}
@@ -334,26 +341,22 @@
\alert{Data is usually present in a file!} \\
Lets look at the \typ{pendulum.txt} file.
\begin{lstlisting}
-$ cat pendulum.txt
+In []: cat pendulum.txt
1.0000e-01 6.9004e-01
1.1000e-01 6.9497e-01
1.2000e-01 7.4252e-01
1.3000e-01 7.5360e-01
-1.4000e-01 8.3568e-01
-1.5000e-01 8.6789e-01
\end{lstlisting} %$
\ldots
-\begin{block}{Windows users:}
- C:> type pendulum.txt
-\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{Reading \typ{pendulum.txt}}
\begin{itemize}
+ \item File contains L vs. T values
+ \item First Column - L values
+ \item Second Column - T values
\item Let us generate a plot from the data file
- \item File contains L vs. T values
- \item L - Column1; T - Column2
\end{itemize}
\end{frame}
@@ -361,16 +364,16 @@
\frametitle{Plotting from \typ{pendulum.txt}}
Open a new script and type the following:
\begin{lstlisting}
-l = []
+L = []
t = []
for line in open('pendulum.txt'):
point = line.split()
- l.append(float(point[0]))
+ L.append(float(point[0]))
t.append(float(point[1]))
tsq = []
for time in t:
tsq.append(time*time)
-plot(l, tsq, '.')
+plot(L, tsq, '.')
\end{lstlisting}
\end{frame}
@@ -447,16 +450,16 @@
\begin{frame}[fragile]
\frametitle{Let's review the code}
\begin{lstlisting}
-l = []
+L = []
t = []
for line in open('pendulum.txt'):
point = line.split()
- l.append(float(point[0]))
+ L.append(float(point[0]))
t.append(float(point[1]))
tsq = []
for time in t:
tsq.append(time*time)
-plot(l, tsq, '.')
+plot(L, tsq, '.')
\end{lstlisting}
\end{frame}
--- a/day1/session3.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/session3.tex Fri Apr 02 15:45:07 2010 +0530
@@ -79,7 +79,7 @@
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {28 January, 2010\\Day 1, Session 3}
+\date[] {02 April, 2010\\Day 1, Session 3}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
@@ -145,22 +145,15 @@
In []: g_list = []
In []: for line in open('pendulum.txt'):
.... point = line.split()
- .... l = float(point[0])
+ .... L = float(point[0])
.... t = float(point[1])
- .... g = 4 * pi * pi * l / (t * t)
+ .... g = 4 * pi * pi * L / (t * t)
.... g_list.append(g)
\end{lstlisting}
\end{frame}
-\begin{frame}
- \frametitle{Computing mean ``g''}
- \begin{block}{Exercise}
- Obtain the mean of ``g''
- \end{block}
-\end{frame}
-
\begin{frame}[fragile]
- \frametitle{Mean ``g''}
+ \frametitle{Mean ``g'' - Classical method}
\begin{lstlisting}
In []: total = 0
In []: for g in g_list:
@@ -173,7 +166,7 @@
\end{frame}
\begin{frame}[fragile]
- \frametitle{Mean ``g''}
+ \frametitle{Mean ``g'' - Slightly improved method}
\begin{lstlisting}
In []: g_mean = sum(g_list) / len(g_list)
In []: print 'Mean: ', g_mean
@@ -181,7 +174,7 @@
\end{frame}
\begin{frame}[fragile]
- \frametitle{Mean ``g''}
+ \frametitle{Mean ``g'' - One liner}
\begin{lstlisting}
In []: g_mean = mean(g_list)
In []: print 'Mean: ', g_mean
@@ -215,7 +208,7 @@
\item Region Code
\item Roll Number
\item Name
- \item Marks of 5 subjects: English, Hindi, Maths, Science, Social
+ \item Marks of 5 subjects: SLang, Flang Maths, Science, Social
\item Total marks
\item Pass/Fail (P/F)
\item Withheld (W)
@@ -257,30 +250,33 @@
\subsection{Data processing}
\begin{frame}[fragile]
\frametitle{File reading and parsing \ldots}
+\emphbar{Reading files line by line is the same as we had done with the pendulum example.}
+
\begin{lstlisting}
for record in open('sslc1.txt'):
fields = record.split(';')
\end{lstlisting}
-\begin{block}{}
-\centerline{Recall pendulum example!}
-\end{block}
\end{frame}
\subsection{Dictionaries}
\begin{frame}[fragile]
\frametitle{Dictionaries: Introduction}
\begin{itemize}
- \item lists index: 0 \ldots n
- \item dictionaries index using strings
+ \item Lists index using integers\\
+Recall \typ{p = [2, 3, 5, 7]} and\\
+\typ{p[1]} is equal to \typ{3}
+ \item Dictionaries index using strings
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Dictionaries \ldots}
\begin{lstlisting}
-In []: d = {'jpg' : 'image file',
+In []: d = {'png' : 'image file',
'txt' : 'text file',
- 'py' : 'python code'}
+ 'py' : 'python code',
+ 'java': 'bad code',
+ 'cpp': 'complex code'}
In []: d['txt']
Out[]: 'text file'
@@ -293,21 +289,24 @@
In []: 'py' in d
Out[]: True
-In []: 'cpp' in d
+In []: 'jpg' in d
Out[]: False
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Dictionaries \ldots}
- \begin{lstlisting}
+ \begin{small}
+ \begin{lstlisting}
In []: d.keys()
-Out[]: ['py', 'txt', 'jpg']
+Out[]: ['cpp', 'py', 'txt', 'java', 'png']
In []: d.values()
-Out[]: ['python code', 'text file',
- 'image file']
- \end{lstlisting}
+Out[]: ['complex code', 'python code',
+ 'text file', 'bad code',
+ 'image file']
+ \end{lstlisting}
+ \end{small}
\inctime{10}
\end{frame}
@@ -319,7 +318,7 @@
\end{lstlisting}
\begin{itemize}
\item Keys will be region codes
- \item Values will be the number students who scored more than 90\% in that region
+ \item Values will be the number students who scored more than 90\% in that region in Science
\end{itemize}
\begin{block}{Sample \emph{science} dictionary}
\{'A': 729, 'C': 764, 'B': 1120,'E': 414, 'D': 603, 'F': 500\}
@@ -366,6 +365,14 @@
\subsection{Visualizing data}
\begin{frame}[fragile]
+ \frametitle{Pie Chart}
+ \begin{lstlisting}
+ pie(science.values())
+ \end{lstlisting}
+\includegraphics[height=2in, interpolate=true]{data/science_nolabel}
+\end{frame}
+
+\begin{frame}[fragile]
\frametitle{Pie chart}
\small
\begin{lstlisting}
@@ -408,13 +415,6 @@
\subsection{Obtaining statistics}
\begin{frame}[fragile]
\frametitle{Obtaining statistics}
- \begin{block}{Exercise}
- Obtain the mean of Math scores
- \end{block}
-\end{frame}
-
-\begin{frame}[fragile]
- \frametitle{Obtaining statistics}
\begin{lstlisting}
print 'Mean: ', mean(math_scores)
--- a/day1/session4.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/session4.tex Fri Apr 02 15:45:07 2010 +0530
@@ -79,7 +79,7 @@
\author[FOSSEE] {FOSSEE}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {28 January, 2010\\Day 1, Session 4}
+\date[] {02 April, 2010\\Day 1, Session 4}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
@@ -164,13 +164,14 @@
array([[ 1., 0.],
[ 0., 1.]])
\end{lstlisting}
-Also available \alert{\typ{zeros, zeros_like, empty, empty_like}}
+Also available \alert{\typ{zeros, zeros_like}}
\end{small}
\end{frame}
\begin{frame}[fragile]
\frametitle{Accessing elements}
+ \begin{small}
\begin{lstlisting}
In []: c
Out[]:
@@ -182,9 +183,11 @@
Out[]: 23
In []: c[1,2]
Out[]: 23
+
In []: c[1]
Out[]: array([21, 22, 23])
\end{lstlisting}
+ \end{small}
\end{frame}
\begin{frame}[fragile]
@@ -206,7 +209,7 @@
[31, 32, 33]])
\end{lstlisting}
\end{small}
-How to change one \alert{column}?
+How to access one \alert{column}?
\end{frame}
\begin{frame}[fragile]
@@ -279,23 +282,43 @@
\end{frame}
\begin{frame}[fragile]
- \frametitle{Slicing \& Striding Exercises}
+ \frametitle{Shape of a matrix}
+ \begin{lstlisting}
+In []: c
+Out[]:
+array([[11, 12, 13],
+ [ 0, 0, 0],
+ [31, 32, 33]])
+
+In []: c.shape
+Out[]: (3, 3)
+ \end{lstlisting}
+\emphbar{Shape specifies shape or dimensions of a matrix}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Elementary image processing}
\begin{small}
\begin{lstlisting}
In []: a = imread('lena.png')
In []: imshow(a)
Out[]: <matplotlib.image.AxesImage object at 0xa0384cc>
+ \end{lstlisting}
+ \end{small}
+\typ{imread} returns an array of shape (512, 512, 4) which represents an image of 512x512 pixels and 4 shades.\\
+\typ{imshow} renders the array as an image.
+\end{frame}
- \end{lstlisting}
-\end{small}
+\begin{frame}[fragile]
+\frametitle{Slicing \& Striding Exercises}
\begin{itemize}
\item Crop the image to get the top-left quarter
\item Crop the image to get only the face
\item Resize image to half by dropping alternate pixels
\end{itemize}
+
\end{frame}
-
\begin{frame}[fragile]
\frametitle{Solutions}
\begin{small}
@@ -330,14 +353,6 @@
\end{frame}
\begin{frame}[fragile]
- \frametitle{Sum of all elements}
- \begin{lstlisting}
-In []: sum(a)
-Out[]: 12
- \end{lstlisting}
-\end{frame}
-
-\begin{frame}[fragile]
\frametitle{Matrix Addition}
\begin{lstlisting}
In []: b = array([[3,2,-1,5],
@@ -381,10 +396,11 @@
\begin{frame}[fragile]
\frametitle{Inverse of a Matrix}
\begin{lstlisting}
-In []: inv(a)
+
\end{lstlisting}
\begin{small}
\begin{lstlisting}
+In []: inv(a)
Out[]:
array([[-0.5 , 0.55, -0.15, 0.7 ],
[ 0.75, -0.5 , 0.5 , -0.75],
@@ -392,14 +408,20 @@
[ 0.25, -0.25, 0.25, -0.25]])
\end{lstlisting}
\end{small}
+\emphbar{Try this: \typ{I = dot(a, inv(a))}}
\end{frame}
\begin{frame}[fragile]
-\frametitle{Determinant}
+\frametitle{Determinant and sum of all elements}
\begin{lstlisting}
In []: det(a)
Out[]: 80.0
\end{lstlisting}
+ \begin{lstlisting}
+In []: sum(a)
+Out[]: 12
+ \end{lstlisting}
+
\end{frame}
%%use S=array(X,Y)
@@ -452,7 +474,8 @@
\section{Least Squares Fit}
\begin{frame}[fragile]
\frametitle{$L$ vs. $T^2$ - Scatter}
-\vspace{-0.15in}
+Linear trend visible.
+\vspace{-0.1in}
\begin{figure}
\includegraphics[width=4in]{data/L-Tsq-points}
\end{figure}
@@ -460,37 +483,24 @@
\begin{frame}[fragile]
\frametitle{$L$ vs. $T^2$ - Line}
-\vspace{-0.15in}
+This line does not make any mathematical sense.
+\vspace{-0.1in}
\begin{figure}
\includegraphics[width=4in]{data/L-Tsq-Line}
\end{figure}
\end{frame}
\begin{frame}[fragile]
-\frametitle{$L$ vs. $T^2$ }
\frametitle{$L$ vs. $T^2$ - Least Square Fit}
-\vspace{-0.15in}
+This is what our intention is.
+\vspace{-0.1in}
\begin{figure}
\includegraphics[width=4in]{data/least-sq-fit}
\end{figure}
\end{frame}
-\begin{frame}
-\frametitle{Least Square Fit Curve}
-\begin{center}
-\begin{itemize}
-\item $L \alpha T^2$
-\item Best Fit Curve $\rightarrow$ Linear
- \begin{itemize}
- \item Least Square Fit
- \end{itemize}
-\item \typ{lstsq()}
-\end{itemize}
-\end{center}
-\end{frame}
-
\begin{frame}[fragile]
-\frametitle{\typ{lstsq}}
+\frametitle{Matrix Formulation}
\begin{itemize}
\item We need to fit a line through points for the equation $T^2 = m \cdot L+c$
\item In matrix form, the equation can be represented as $T_{sq} = A \cdot p$, where $T_{sq}$ is
@@ -518,13 +528,13 @@
\begin{frame}[fragile]
\frametitle{Getting $L$ and $T^2$}
-If you \alert{closed} IPython after session 2
+%If you \alert{closed} IPython after session 2
\begin{lstlisting}
-In []: l = []
+In []: L = []
In []: t = []
In []: for line in open('pendulum.txt'):
.... point = line.split()
- .... l.append(float(point[0]))
+ .... L.append(float(point[0]))
.... t.append(float(point[1]))
....
....
@@ -534,7 +544,7 @@
\begin{frame}[fragile]
\frametitle{Getting $L$ and $T^2$ \dots}
\begin{lstlisting}
-In []: l = array(l)
+In []: L = array(L)
In []: t = array(t)
\end{lstlisting}
\alert{\typ{In []: tsq = t*t}}
@@ -543,7 +553,7 @@
\begin{frame}[fragile]
\frametitle{Generating $A$}
\begin{lstlisting}
-In []: A = array([l, ones_like(l)])
+In []: A = array([L, ones_like(L)])
In []: A = A.T
\end{lstlisting}
%% \begin{itemize}
@@ -571,13 +581,15 @@
\frametitle{Least Square Fit Line \ldots}
We get the points of the line from \typ{coef}
\begin{lstlisting}
-In []: Tline = coef[0]*l + coef[1]
+In []: Tline = coef[0]*L + coef[1]
+
+In []: Tline.shape
\end{lstlisting}
\begin{itemize}
-\item Now plot \typ{Tline} vs. \typ{l}, to get the Least squares fit line.
+\item Now plot \typ{Tline} vs. \typ{L}, to get the Least squares fit line.
\end{itemize}
\begin{lstlisting}
-In []: plot(l, Tline)
+In []: plot(L, Tline)
\end{lstlisting}
\end{frame}
--- a/day1/session5.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/session5.tex Fri Apr 02 15:45:07 2010 +0530
@@ -78,7 +78,7 @@
\author[FOSSEE] {FOSSEE}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {28 January, 2010\\Day 1, Session 5}
+\date[] {02 April, 2010\\Day 1, Session 5}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
@@ -151,14 +151,17 @@
\begin{columns}
\column{0.5\textwidth}
\hspace*{-0.5in}
- \includegraphics[height=2in, interpolate=true]{data/points}
+ \includegraphics[height=2in, interpolate=true]{data/triangle}
\column{0.45\textwidth}
\begin{block}{Line between two points}
\tiny
\begin{lstlisting}
-In []: x = [1, 5]
-In []: y = [1, 4]
+In []: x = [3, 1]
+In []: y = [2, -3]
+In []: z = [-2, 4]
In []: plot(x, y)
+In []: plot(y, z)
+In []: plot(x, z)
\end{lstlisting}
\end{block}
\end{columns}
@@ -189,7 +192,7 @@
\begin{frame}[fragile]
\frametitle{Problem 3 cont...}
-Create a sequence of images in which the damped oscillator($e^{x/10}sin(x)$) slowly evolves over time.
+Create a sequence of images in which the damped oscillator($e^{-x/10}sin(x)$) slowly evolves over time.
\begin{columns}
\column{0.35\textwidth}
\includegraphics[width=1.5in,height=1.5in, interpolate=true]{data/plot2}
--- a/day1/session6.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day1/session6.tex Fri Apr 02 15:45:07 2010 +0530
@@ -78,7 +78,7 @@
\author[FOSSEE] {FOSSEE}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {28 January, 2010\\Day 1, Session 6}
+\date[] {02 April, 2010\\Day 1, Session 6}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
@@ -239,7 +239,7 @@
\begin{frame}[fragile]
\frametitle{\typ{fsolve}}
-Find the root of $sin(x)+cos^2(x)$ nearest to $0$
+Find the root of $sin(z)+cos^2(z)$ nearest to $0$
\vspace{-0.1in}
\begin{center}
\includegraphics[height=2.8in, interpolate=true]{data/fsolve}
@@ -248,18 +248,18 @@
\begin{frame}[fragile]
\frametitle{\typ{fsolve}}
-Root of $sin(x)+cos^2(x)$ nearest to $0$
+Root of $sin(z)+cos^2(z)$ nearest to $0$
\begin{lstlisting}
-In []: fsolve(sin(x)+cos(x)*cos(x), 0)
-NameError: name 'x' is not defined
+In []: fsolve(sin(z)+cos(z)*cos(z), 0)
+NameError: name 'z' is not defined
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{\typ{fsolve}}
\begin{lstlisting}
-In []: x = linspace(-pi, pi)
-In []: fsolve(sin(x)+cos(x)*cos(x), 0)
+In []: z = linspace(-pi, pi)
+In []: fsolve(sin(z)+cos(z)*cos(z), 0)
\end{lstlisting}
\begin{small}
\alert{\typ{TypeError:}}
@@ -271,8 +271,8 @@
\frametitle{Functions - Definition}
We have been using them all along. Now let's see how to define them.
\begin{lstlisting}
-In []: def f(x):
- return sin(x)+cos(x)*cos(x)
+In []: def f(z):
+ return sin(z)+cos(z)*cos(z)
\end{lstlisting}
\begin{itemize}
\item \typ{def}
@@ -285,7 +285,7 @@
\begin{frame}[fragile]
\frametitle{Functions - Calling them}
\begin{lstlisting}
-In [15]: f()
+In []: f()
---------------------------------------
\end{lstlisting}
\alert{\typ{TypeError:}}\typ{f() takes exactly 1 argument}
@@ -301,7 +301,7 @@
\begin{frame}[fragile]
\frametitle{\typ{fsolve} \ldots}
-Find the root of $sin(x)+cos^2(x)$ nearest to $0$
+Find the root of $sin(z)+cos^2(z)$ nearest to $0$
\begin{lstlisting}
In []: fsolve(f, 0)
Out[]: -0.66623943249251527
@@ -311,6 +311,25 @@
\end{center}
\end{frame}
+\begin{frame}[fragile]
+ \frametitle{Exercise Problem}
+ Find the root of the equation $x^2 - sin(x) + cos^2(x) == tan(x)$ nearest to $0$
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Solution}
+ \begin{small}
+ \begin{lstlisting}
+def f(x):
+ return x**2 - sin(x) + cos(x)*cos(x) - tan(x)
+fsolve(f, 0)
+ \end{lstlisting}
+ \end{small}
+ \begin{center}
+\includegraphics[height=2in, interpolate=true]{data/fsolve_tanx}
+ \end{center}
+\end{frame}
+
%% \begin{frame}[fragile]
%% \frametitle{Scipy Methods \dots}
%% \begin{small}
--- a/day1/tot.tex Thu Feb 04 19:36:17 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,314 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%Tutorial slides on Python.
-%
-% Author: FOSSEE
-% Copyright (c) 2009, FOSSEE, IIT Bombay
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-\documentclass[14pt,compress]{beamer}
-%\documentclass[draft]{beamer}
-%\documentclass[compress,handout]{beamer}
-%\usepackage{pgfpages}
-%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
-
-% Modified from: generic-ornate-15min-45min.de.tex
-\mode<presentation>
-{
- \usetheme{Warsaw}
- \useoutertheme{infolines}
- \setbeamercovered{transparent}
-}
-
-\usepackage[english]{babel}
-\usepackage[latin1]{inputenc}
-%\usepackage{times}
-\usepackage[T1]{fontenc}
-
-% Taken from Fernando's slides.
-\usepackage{ae,aecompl}
-\usepackage{mathpazo,courier,euler}
-\usepackage[scaled=.95]{helvet}
-
-\definecolor{darkgreen}{rgb}{0,0.5,0}
-
-\usepackage{listings}
-\lstset{language=Python,
- basicstyle=\ttfamily\bfseries,
- commentstyle=\color{red}\itshape,
- stringstyle=\color{darkgreen},
- showstringspaces=false,
- keywordstyle=\color{blue}\bfseries}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Macros
-\setbeamercolor{emphbar}{bg=blue!20, fg=black}
-\newcommand{\emphbar}[1]
-{\begin{beamercolorbox}[rounded=true]{emphbar}
- {#1}
- \end{beamercolorbox}
-}
-\newcounter{time}
-\setcounter{time}{0}
-\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
-
-\newcommand{\typ}[1]{\lstinline{#1}}
-
-\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
-
-%%% This is from Fernando's setup.
-% \usepackage{color}
-% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
-% % Use and configure listings package for nicely formatted code
-% \usepackage{listings}
-% \lstset{
-% language=Python,
-% basicstyle=\small\ttfamily,
-% commentstyle=\ttfamily\color{blue},
-% stringstyle=\ttfamily\color{orange},
-% showstringspaces=false,
-% breaklines=true,
-% postbreak = \space\dots
-% }
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Title page
-\title[Tricks of the trade]{Python for Science and Engg: Tricks of the trade}
-
-\author[FOSSEE] {FOSSEE}
-
-\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {28 January, 2010\\Day 1, Tricks of the Trade}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
-%\logo{\pgfuseimage{iitmlogo}}
-
-
-%% Delete this, if you do not want the table of contents to pop up at
-%% the beginning of each subsection:
-\AtBeginSubsection[]
-{
- \begin{frame}<beamer>
- \frametitle{Outline}
- \tableofcontents[currentsection,currentsubsection]
- \end{frame}
-}
-
-\AtBeginSection[]
-{
- \begin{frame}<beamer>
- \frametitle{Outline}
- \tableofcontents[currentsection,currentsubsection]
- \end{frame}
-}
-
-% If you wish to uncover everything in a step-wise fashion, uncomment
-% the following command:
-%\beamerdefaultoverlayspecification{<+->}
-
-%%\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% DOCUMENT STARTS
-\begin{document}
-
-\begin{frame}
- \maketitle
-\end{frame}
-
-%% \begin{frame}
-%% \frametitle{Outline}
-%% \tableofcontents
-%% % You might wish to add the option [pausesections]
-%% \end{frame}
-
-\begin{frame}
- \frametitle{Workshop Schedule: Day 1}
- \begin{description}
- \item[Tricks of the trade] Thu 09:00--09:30
- \item[Session 1] Thu 09:30--10:30
- \item[Session 2] Thu 10:45--11:45
- \item[Session 3] Thu 11:50--12:30
- \item[Session 4] Thu 12:30--1:30
- \item[Quiz 1] Thu 14:30--14:45
- \item[Exercises] Thu 14:45--15:30
- \item[Session 5] Thu 15:45--16:45
- \item[Quiz 2] Thu 16:50--17:05
- \end{description}
-\end{frame}
-
-\begin{frame}
- \frametitle{Workshop Schedule: Day 2}
- \begin{description}
- \item[Session 1] Fri 09:00--10:00
- \item[Session 2] Fri 10:05--11:05
- \item[Session 3] Fri 11:20--12:20
- \item[Session 4] Fri 12:25--13:25
- \item[Quiz 1] Fri 14:25--14:40
- \item[Exercises] Fri 14:40--15:25
- \item[Session 5] Fri 15:40--16:40
- \item[Quiz 2] Fri 16:45--17:00
- \end{description}
-\end{frame}
-
-\section{Checklist}
-\begin{frame}
-\frametitle{Checklist}
- \begin{enumerate}
- \item IPython
- \item Editor
- \item Data files:
- \begin{itemize}
- \item \typ{sslc1.txt}
- \item \typ{pendulum.txt}
- \item \typ{points.txt}
- \item \typ{pos.txt}
- \item \typ{holmes.txt}
- \end{itemize}
- \item Python scripts:
- \begin{itemize}
- \item \typ{sslc_allreg.py}
- \item \typ{sslc_science.py}
- \end{itemize}
- \item Images
- \begin{itemize}
- \item \typ{lena.png}
- \item \typ{smoothing.gif}
- \end{itemize}
- \end{enumerate}
-\end{frame}
-
-\section{Starting up Ipython}
-\begin{frame}[fragile]
-\frametitle{Starting up \ldots}
-\begin{block}{}
-\begin{lstlisting}
- $ ipython -pylab
-\end{lstlisting} %$
-\end{block}
-\begin{lstlisting}
- In []: print "Hello, World!"
- Hello, World!
-\end{lstlisting}
-Exiting
-\begin{lstlisting}
- In []: ^D(Ctrl-D)
- Do you really want to exit([y]/n)? y
-\end{lstlisting}
-\end{frame}
-
-\section{Loops}
-\begin{frame}[fragile]
-\frametitle{Loops}
-Breaking out of loops
-\begin{lstlisting}
- In []: while True:
- ...: print "Hello, World!"
- ...:
- Hello, World!
- Hello, World!^C(Ctrl-C)
- ------------------------------------
- KeyboardInterrupt
-\end{lstlisting}
-\end{frame}
-
-\section{Indentation}
-\begin{frame}[fragile]
- \frametitle{Indentation}
- \begin{lstlisting}
- In []: while True:
- ...: print "Hello, World!"
- ...:
- \end{lstlisting}
-\emphbar{\alert{Indentation: Notice the 4 spaces before\\} \typ{print "Hello, World!"}\\
- Hit the ``ENTER'' key twice to return to the previous indentation level}
-\end{frame}
-
-\section{Tab Completion}
-\begin{frame}[fragile]
- \frametitle{Tab Completion}
- Type \typ{pri} and hit the Tab key
- \begin{lstlisting}
- In []: pri <Tab>
- In []: print
- \end{lstlisting}
- Type \typ{whi} and hit the Tab key
- \begin{lstlisting}
- In []: whi <Tab>
- In []: while
- \end{lstlisting}
-\end{frame}
-
-\section{Tab Suggestions}
-\begin{frame}[fragile]
- \frametitle{Tab Suggestions}
- \begin{lstlisting}
-In []: a = 'Hello world'
-
-In []: a.<Tab>
- \end{lstlisting}
- \ldots
-\end{frame}
-
-\section{Command history}
-\begin{frame}[fragile]
- \frametitle{Command history}
- \typ{In []:} \alert{$\uparrow$}\\
- \typ{In []: a = 'Hello world'}\\
- \emphbar{The previously entered commands can be browsed using the \alert{$\uparrow$} key.}
-\end{frame}
-
-\section{Saving Commands}
-\begin{frame}[fragile]
-\frametitle{History and Saving of Commands}
-\begin{itemize}
-\item \typ{\%hist} gives history of commands in a session
-\item \typ{\%save} can be used to save the commands
-\end{itemize}
-\begin{block}{Careful about errors!}
- \kwrd{\%hist} will contain the errors as well,\\
- so be careful while selecting line numbers.
-\end{block}
-\end{frame}
-
-\section{Editors}
-\begin{frame}[fragile]
- \frametitle{Editors}
- The following are some good editors:
- \begin{itemize}
- \item emacs
- \item vim
- \item \alert{scite} - we recommend it
- \end{itemize}
-\end{frame}
-
-\section{Scite - How to}
-\begin{frame}[fragile]
- \frametitle{Scite - How to \ldots}
- \begin{itemize}
- \item Opening scite
- \begin{itemize}
- \item GNU/Linux: \alert{Applications} $\rightarrow$ \alert{Programming} $\rightarrow$ \alert{SciTE Text Editor}
- \item Windows: Double click on the \alert{SciTE} Desktop icon
- \end{itemize}
- \item Type the contents
- \item Saving the file with a filename \alert{File $\rightarrow$ Save as}
- \item Saving the file \alert{File $\rightarrow$ Save}
- \item Exiting the editor \alert{File $\rightarrow$ Exit}
- \item To open an existing file: \alert{File $\rightarrow$ Open}
- \end{itemize}
-\end{frame}
-
-\section{Summary}
-\begin{frame}[fragile]
- \frametitle{What did we learn?}
- \begin{itemize}
- \item Starting up IPython
- \item Loops - Indentation and breaking out of loops
- \item \kwrd{\%hist} - History of commands
- \item \kwrd{\%save} - Saving commands
- \item Using SciTE
- \end{itemize}
-\end{frame}
-
-\end{document}
--- a/day2/day2quiz.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day2/day2quiz.tex Fri Apr 02 15:45:07 2010 +0530
@@ -40,7 +40,7 @@
\author[FOSSEE Team] {FOSSEE}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {\today \\ Day 2, Quiz 1}
+\date[] {\today \\ Day 2, Quiz}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -57,6 +57,7 @@
\item Name:
\item University/College/Company:
\item Student/Teacher/Professional:
+ \item Field of interest/study:
\end{itemize}
\end{frame}
@@ -84,7 +85,7 @@
\begin{frame}
\frametitle{\incqno }
How do you create a complex number with real part 2 and imaginary part
-0.5.
+0.5 ?
\end{frame}
\begin{frame}
@@ -94,7 +95,7 @@
\begin{frame}
\frametitle{\incqno }
- What does '*' * 40 produce?
+ What does 't' * 40 produce?
\end{frame}
\begin{frame}[fragile]
@@ -133,7 +134,7 @@
\begin{lstlisting}
In []: a = {'a': 1, 'b': 2}
In []: a['a'] = 10
-pIn []: print a
+In []: print a
\end{lstlisting}
What is the output?
\end{frame}
@@ -162,7 +163,7 @@
In []: a = (1, 2, 3)
In []: a[1] = 10
\end{lstlisting}
- What is the result?
+ What is the output?
\end{frame}
\begin{frame}[fragile]
@@ -183,4 +184,3 @@
\end{frame}
\end{document}
-
--- a/day2/session1.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day2/session1.tex Fri Apr 02 15:45:07 2010 +0530
@@ -79,7 +79,7 @@
\author[FOSSEE Team] {The FOSSEE Group}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {29 January, 2010\\Day 2, Session 1}
+\date[] {09 March, 2010\\Day 2, Session 1}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
@@ -275,6 +275,9 @@
\begin{lstlisting}
In []: ''.join(['a', 'b', 'c'])
Out[]: 'abc'
+
+In []: ', '.join(['a', 'b', 'c'])
+Out[]: 'a, b, c'
\end{lstlisting}
\end{frame}
@@ -376,7 +379,7 @@
--------------------------------------------
TypeError Traceback (most recent call last)
-/<ipython console> in <module>()
+<ipython console> in <module>()
TypeError: can`t multiply sequence by
non-int of type `str`
@@ -508,7 +511,7 @@
\subsection{Basic Conditional flow}
\begin{frame}[fragile]
\frametitle{\typ{If...elif...else} example}
-Type out the code below in an editor.
+Type the following code in an editor \& save as \alert{ladder.py}
\small
\begin{lstlisting}
x = int(raw_input("Enter an integer:"))
--- a/day2/session2.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day2/session2.tex Fri Apr 02 15:45:07 2010 +0530
@@ -78,7 +78,7 @@
\author[FOSSEE Team] {The FOSSEE Group}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {12 January, 2010\\Day 2, Session 2}
+\date[] {09 March, 2010\\Day 2, Session 2}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
@@ -153,9 +153,7 @@
\begin{block}{Documentation convention}
\begin{itemize}
\item \alert{Anything within \typ{[]} is optional}
- \begin{itemize}
- \item Nothing to do with Python.
- \end{itemize}
+ \item Nothing to do with Python.
\end{itemize}
\end{block}
\end{frame}
@@ -208,19 +206,6 @@
\item It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops.
\end{enumerate}
Write a program that accepts the starting value and prints out the Collatz sequence.
-\end{frame}
-
-\begin{frame}[fragile]{Problem 1.3}
- Write a program that prints the following pyramid on the screen.
- \begin{lstlisting}
-1
-2 2
-3 3 3
-4 4 4 4
- \end{lstlisting}
-The number of lines must be obtained from the user.\\
-\pause
-\emphbar{When can your code fail?}
\inctime{5}
\end{frame}
@@ -232,37 +217,37 @@
\begin{lstlisting}
num = [1, 2, 3, 4]
\end{lstlisting}
-\centerline{is a list}
+is a list
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{Lists: methods}
\begin{lstlisting}
-In []: num = [1, 2, 3, 4]
+In []: num = [9, 8, 2, 3, 7]
-In []: num + [9, 10, 11]
-Out[]: [1, 2, 3, 4, 9, 10, 11]
+In []: num + [4, 5, 6]
+Out[]: [9, 8, 2, 3, 7, 4, 5, 6]
-In []: num.append([9, 10, 11])
+In []: num.append([4, 5, 6])
In []: num
-Out[]: [1, 2, 3, 4, [9, 10, 11]]
+Out[]: [9, 8, 2, 3, 7, [4, 5, 6]]
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Lists: methods}
\begin{lstlisting}
-In []: num = [1, 2, 3, 4]
+In []: num = [9, 8, 2, 3, 7]
-In []: num.extend([5, 6, 7])
+In []: num.extend([4, 5, 6])
In []: num
-Out[]: [1, 2, 3, 4, 5, 6, 7]
+Out[]: [9, 8, 2, 3, 7, 4, 5, 6]
In []: num.reverse()
In []: num
-Out[]: [7, 6, 5, 4, 3, 2, 1]
+Out[]: [6, 5, 4, 7, 3, 2, 8, 9]
In []: num.remove(6)
In []: num
@@ -307,16 +292,17 @@
\begin{frame}[fragile]
\frametitle{List containership}
+\emphbar{Recall \typ{num} is \typ{[9, 8, 2, 3, 7]}}
\begin{lstlisting}
In []: 4 in num
+Out[]: False
+
+In []: b = 8
+In []: b in num
Out[]: True
-In []: b = 15
-In []: b in num
+In []: b not in num
Out[]: False
-
-In []: b not in num
-Out[]: True
\end{lstlisting}
\end{frame}
@@ -399,7 +385,7 @@
\end{frame}
\begin{frame} {Problem Set 2.1: Problem 2.1.1}
-You are given date strings of the form ``29 Jul, 2009'', or ``4 January 2008''. In other words a number, a string and another number, with a comma sometimes separating the items.\\Write a function that takes such a string and returns a tuple (yyyy, mm, dd) where all three elements are ints.
+You are given date strings of the form ``29 Jul, 2009'', or ``4 January 2008''. In other words a number, a string and another number, with a comma sometimes separating the items.\\Write a program that takes such a string as input and prints a tuple (yyyy, mm, dd) where all three elements are ints.
\end{frame}
\subsection{Sets}
@@ -465,7 +451,6 @@
\frametitle{Problem 2.2.2}
Given a list of words, find all the anagrams in the list.
-\inctime{15}
\end{frame}
\section{Functions}
@@ -519,6 +504,24 @@
\end{lstlisting}
\end{frame}
+\begin{frame}[fragile]
+ \frametitle {What does this function do?}
+ \begin{lstlisting}
+def what( x, n ):
+ if n < 0:
+ n = -n
+ x = 1.0 / x
+
+ z = 1.0
+ while n > 0:
+ if n % 2 == 1:
+ z *= x
+ x *= x
+ n /= 2
+ return z
+ \end{lstlisting}
+\end{frame}
+
\begin{frame}
\frametitle{What did we learn?}
\begin{itemize}
--- a/day2/session3.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day2/session3.tex Fri Apr 02 15:45:07 2010 +0530
@@ -78,7 +78,7 @@
\author[FOSSEE Team] {The FOSSEE Group}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {12 January, 2010\\Day 2, Session 3}
+\date[] {09 March, 2010\\Day 2, Session 3}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
@@ -256,6 +256,7 @@
\end{frame}
\begin{frame}[fragile]
+ \frametitle{Now what?}
\begin{lstlisting}
Traceback (most recent call last):
File "four_plot.py", line 1, in <module>
--- a/day2/session4.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day2/session4.tex Fri Apr 02 15:45:07 2010 +0530
@@ -100,7 +100,7 @@
\author[FOSSEE] {FOSSEE}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {12 January, 2010\\Day 2, Session 4}
+\date[] {09 March, 2010\\Day 2, Session 4}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitblogo}{iitblogo}
--- a/day2/session5.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day2/session5.tex Fri Apr 02 15:45:07 2010 +0530
@@ -78,7 +78,7 @@
\author[FOSSEE] {FOSSEE}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {12 January, 2010\\Day 2, Session 5}
+\date[] {09 March, 2010\\Day 2, Session 5}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
--- a/day2/session6.tex Thu Feb 04 19:36:17 2010 +0530
+++ b/day2/session6.tex Fri Apr 02 15:45:07 2010 +0530
@@ -100,7 +100,7 @@
\author[FOSSEE] {FOSSEE}
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
-\date[] {12 January, 2010\\Day 2, Session 6}
+\date[] {09 March, 2010\\Day 2, Session 6}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%