# HG changeset patch # User Santosh G. Vattam # Date 1266829321 -19800 # Node ID f04eca8b2f3d4142a284929c63a342f0ed045a80 # Parent 5f02dfb93df10c2c107375cb852bd5555a451f44 Commits from NIT DGP and IITK diff -r 5f02dfb93df1 -r f04eca8b2f3d day1/day1quiz1.tex --- a/day1/day1quiz1.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day1/day1quiz1.tex Mon Feb 22 14:32:01 2010 +0530 @@ -74,6 +74,7 @@ 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} diff -r 5f02dfb93df1 -r f04eca8b2f3d day1/day1quiz2.tex --- a/day1/day1quiz2.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day1/day1quiz2.tex Mon Feb 22 14:32:01 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} diff -r 5f02dfb93df1 -r f04eca8b2f3d day1/session1.tex --- a/day1/session1.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day1/session1.tex Mon Feb 22 14:32:01 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[] {12 February, 2010\\Day 1, Session 1} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -123,6 +123,65 @@ %% \end{frame} \begin{frame} + \frametitle{Workshop Schedule: Day 1} + \begin{description} + \item[Session 1] Fri 14:00--15:00 + \item[Session 2] Fri 15:05--16:05 + \item[Session 3] Fri 16:10--17:10 + \item[Quiz 1] Fri 17:10--17:25 + \item[Exercises] Thu 17:30--18:00 + \end{description} +\end{frame} + +\begin{frame} + \frametitle{Workshop Schedule: Day 2} + \begin{description} + \item[Session 1] Sat 09:00--10:00 + \item[Session 2] Sat 10:05--11:05 + \item[Session 3] Sat 11:20--12:20 + \item[Quiz 2] Fri 14:25--14:40 + \end{description} +\end{frame} + +\begin{frame} + \frametitle{Workshop Schedule: Day 3} + \begin{description} + \item[Session 1] Sun 09:00--10:00 + \item[Session 2] Sun 10:05--11:05 + \item[Session 3] Sun 11:20--12:20 + \item[Quiz 3] Sun 12:20--12:30 + \item[Exercises] Sun 12:30--13: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} + +\begin{frame} \frametitle{About the Workshop} \begin{block}{Intended Audience} \begin{itemize} @@ -140,6 +199,40 @@ \end{block} \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{Plotting} \subsection{Drawing plots} \begin{frame}[fragile] @@ -301,8 +394,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 +407,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} @@ -345,8 +440,7 @@ \end{lstlisting} \emphbar{Set the axes limits} \begin{lstlisting} -In []: xmax = 2*pi -In []: xlim(xmin, xmax) +In []: xlim(xmin, 2*pi) In []: ylim(ymin-0.2, ymax+0.2) \end{lstlisting} \end{frame} @@ -398,9 +492,9 @@ \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 Use \typ{\%hist} command of IPython \item Identify the required line numbers -\item Then, use \typ{\%save} command of IPython (Recall \%\typ{save} from the previous session) +\item Then, use \typ{\%save} command of IPython \end{itemize} \typ{In []: \%hist}\\ \typ{In []: \%save four_plot.py} \alert{\typ{16 18-27}} @@ -421,6 +515,9 @@ \begin{frame}[fragile] \frametitle{What did we learn?} \begin{itemize} + \item Starting up IPython + \item \kwrd{\%hist} - History of commands + \item \kwrd{\%save} - Saving commands \item Running a script using \kwrd{\%run -i} \item Creating simple plots. \item Adding labels and legends. diff -r 5f02dfb93df1 -r f04eca8b2f3d day1/session2.tex --- a/day1/session2.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day1/session2.tex Mon Feb 22 14:32:01 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[] {12 February, 2010\\Day 1, Session 2} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -208,43 +208,45 @@ \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[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} @@ -299,6 +301,12 @@ \begin{lstlisting} In []: tsq = [] +In []: len(l) +Out[]: 9 + +In []: len(t) +Out[]: 9 + In []: for time in t: ....: tsq.append(time*time) ....: @@ -312,14 +320,15 @@ \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 []: print tsq, len(tsq) + In []: plot(l, tsq) \end{lstlisting} \end{frame} diff -r 5f02dfb93df1 -r f04eca8b2f3d day1/session3.tex --- a/day1/session3.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day1/session3.tex Mon Feb 22 14:32:01 2010 +0530 @@ -79,7 +79,7 @@ \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {28 January, 2010\\Day 1, Session 3} +\date[] {12 February, 2010\\Day 1, Session 3} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -319,7 +319,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\} diff -r 5f02dfb93df1 -r f04eca8b2f3d day1/session4.tex --- a/day1/session4.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day1/session4.tex Mon Feb 22 14:32:01 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[] {13 February, 2010\\Day 2, Session 1} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -279,6 +279,21 @@ \end{frame} \begin{frame}[fragile] + \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{Slicing \& Striding Exercises} \begin{small} \begin{lstlisting} @@ -518,7 +533,7 @@ \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 []: t = [] diff -r 5f02dfb93df1 -r f04eca8b2f3d day1/session5.tex --- a/day1/session5.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day1/session5.tex Mon Feb 22 14:32:01 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[] {12 February, 2010\\Day 1, Session 5} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -189,7 +189,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} diff -r 5f02dfb93df1 -r f04eca8b2f3d day1/session6.tex --- a/day1/session6.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day1/session6.tex Mon Feb 22 14:32:01 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[] {13 February, 2010\\Day 2, Session 2} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} diff -r 5f02dfb93df1 -r f04eca8b2f3d day2/day2quiz.tex --- a/day2/day2quiz.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day2/day2quiz.tex Mon Feb 22 14:32:01 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} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -94,7 +94,7 @@ \begin{frame} \frametitle{\incqno } - What does '*' * 40 produce? + What does 't' * 40 produce? \end{frame} \begin{frame}[fragile] diff -r 5f02dfb93df1 -r f04eca8b2f3d day2/session1.tex --- a/day2/session1.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day2/session1.tex Mon Feb 22 14:32:01 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[] {13 February, 2010\\Day 2, Session 3} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\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} @@ -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:")) diff -r 5f02dfb93df1 -r f04eca8b2f3d day2/session2.tex --- a/day2/session2.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day2/session2.tex Mon Feb 22 14:32:01 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[] {13 February, 2010\\Day 3, Session 1} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -208,19 +208,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} @@ -519,6 +506,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} diff -r 5f02dfb93df1 -r f04eca8b2f3d day2/session3.tex --- a/day2/session3.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day2/session3.tex Mon Feb 22 14:32:01 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[] {13 February, 2010\\Day 3, Session 2} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} diff -r 5f02dfb93df1 -r f04eca8b2f3d day2/session4.tex --- a/day2/session4.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day2/session4.tex Mon Feb 22 14:32:01 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[] {13 February, 2010\\Day 3, Session 4} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitblogo}{iitblogo} diff -r 5f02dfb93df1 -r f04eca8b2f3d day2/session5.tex --- a/day2/session5.tex Thu Jan 28 15:06:24 2010 +0530 +++ b/day2/session5.tex Mon Feb 22 14:32:01 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[] {13 February, 2010\\Day 3, Session 3} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}