diff options
Diffstat (limited to 'day1')
-rw-r--r-- | day1/day1quiz1.tex | 69 | ||||
-rw-r--r-- | day1/day1quiz2.tex | 2 | ||||
-rw-r--r-- | day1/session1.tex | 121 | ||||
-rw-r--r-- | day1/session2.tex | 89 | ||||
-rw-r--r-- | day1/session3.tex | 4 | ||||
-rw-r--r-- | day1/session4.tex | 19 | ||||
-rw-r--r-- | day1/session5.tex | 9 | ||||
-rwxr-xr-x | day1/session6.tex | 2 |
8 files changed, 173 insertions, 142 deletions
diff --git a/day1/day1quiz1.tex b/day1/day1quiz1.tex index ee1fe83..331eb57 100644 --- a/day1/day1quiz1.tex +++ b/day1/day1quiz1.tex @@ -58,24 +58,25 @@ On the top right hand corner please write down the following: \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 +95,18 @@ is in the rectangle $(0, -1.5)$ (left bottom coordinate) and $(2\pi, 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 +135,15 @@ What is the error? How do you fix it? 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 } @@ -211,7 +212,7 @@ Given the above marks, how will you calculate the \alert{mean} and \frametitle{\incqno } \begin{lstlisting} In []: marks = [10, 20, 30, 50, 55, - 75, 83] + 75, 83] \end{lstlisting} How will you convert the list \texttt{marks} to an \alert{array}? \end{frame} diff --git a/day1/day1quiz2.tex b/day1/day1quiz2.tex index 539e1e5..64bc265 100644 --- a/day1/day1quiz2.tex +++ b/day1/day1quiz2.tex @@ -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 --git a/day1/session1.tex b/day1/session1.tex index a6de31a..edd3670 100644 --- a/day1/session1.tex +++ b/day1/session1.tex @@ -77,7 +77,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 1} +\date[] {12 February, 2010\\Day 1, Session 1} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -125,55 +125,41 @@ \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:40 - \item[Exercises] Mon 14:40--15:25 - \item[Session 5] Mon 15:40--16:40 - \item[Quiz 2] Mon 16:45--17:00 + \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] 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:40 - \item[Exercises] Tue 14:40--15:25 - \item[Session 5] Tue 15:40--16:40 - \item[Quiz 2] Tue 16:45--17:00 + \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{About the Workshop} - \begin{block}{Intended Audience} - \begin{itemize} - \item Engg., Mathematics and Science teachers. - \item Interested students from similar streams. - \end{itemize} - \end{block} - - \begin{block}{Goal: Successful participants will be able to} - \begin{itemize} - \item Use Python as plotting, computational tool. - \item Understand how to use Python as a scripting and problem solving language. - \item Train students for the same. - \end{itemize} - \end{block} + \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{Getting started} +\section{Checklist} \begin{frame} \frametitle{Checklist} \begin{enumerate} \item IPython - \item Editor: We recommend \alert{scite}. + \item Editor \item Data files: \begin{itemize} \item \typ{sslc1.txt} @@ -195,6 +181,25 @@ \end{enumerate} \end{frame} +\begin{frame} + \frametitle{About the Workshop} + \begin{block}{Intended Audience} + \begin{itemize} + \item Engg., Mathematics and Science teachers. + \item Interested students from similar streams. + \end{itemize} + \end{block} + + \begin{block}{Goal: Successful participants will be able to} + \begin{itemize} + \item Use Python as plotting, computational tool. + \item Understand how to use Python as a scripting and problem solving language. + \item Train students for the same. + \end{itemize} + \end{block} +\end{frame} + +\section{Starting up Ipython} \begin{frame}[fragile] \frametitle{Starting up \ldots} \begin{block}{} @@ -207,7 +212,7 @@ Hello, World! \end{lstlisting} Exiting -\begin{lstlisting} +\begin{lstlisting} In []: ^D(Ctrl-D) Do you really want to exit([y]/n)? y \end{lstlisting} @@ -235,23 +240,22 @@ Exiting \alert{IPython provides many additional features}\\ \end{frame} -%% \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{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] \frametitle{First Plot} @@ -271,7 +275,6 @@ In []: plot(x, sin(x)) \end{columns} \end{frame} - \begin{frame}[fragile] \frametitle{Walkthrough} \begin{block}{\typ{x = linspace(start, stop, num)} } @@ -413,8 +416,10 @@ In []: figure(1) 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} @@ -424,10 +429,10 @@ In []: close() \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} @@ -457,8 +462,7 @@ In []: ymin, ymax = ylim() \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} @@ -512,7 +516,7 @@ Save commands of review problem into file \begin{itemize} \item Use \typ{\%hist} command of IPython \item Identify the required line numbers -\item Then, use \typ{\%save} command of IPython +\item Then, use \typ{\%save} command of IPython \end{itemize} \typ{In []: \%hist}\\ \typ{In []: \%save four_plot.py} \alert{\typ{16 18-27}} @@ -533,8 +537,9 @@ Save commands of review problem into file \begin{frame}[fragile] \frametitle{What did we learn?} \begin{itemize} - \item \kwrd{\%hist} - \item Saving commands to a script + \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 --git a/day1/session2.tex b/day1/session2.tex index 13efd55..2e493e4 100644 --- a/day1/session2.tex +++ b/day1/session2.tex @@ -78,7 +78,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 2} +\date[] {12 February, 2010\\Day 1, Session 2} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -179,10 +179,10 @@ Out[]: <matplotlib.text.Text object at 0x98746ec> \begin{frame}[fragile] \frametitle{Additional Plotting Attributes} \begin{itemize} - \item \typ{'o'} - Filled circles - \item \typ{'.'} - Small Dots - \item \typ{'-'} - Lines - \item \typ{'--'} - Dashed lines + \item \kwrd{'o'} - Filled circles + \item \kwrd{'.'} - Small Dots + \item \kwrd{'-'} - Lines + \item \kwrd{'- -'} - Dashed lines \end{itemize} \end{frame} @@ -190,7 +190,7 @@ Out[]: <matplotlib.text.Text object at 0x98746ec> \begin{frame}[fragile] \frametitle{Lists: Introduction} \begin{lstlisting} - In []: x = [4, 2, 1, 3] + In []: x = [0, 1, 2, 3] In []: y = [7, 11, 15, 19] @@ -208,43 +208,45 @@ In []: mtlist = [] \end{lstlisting} \emphbar{Empty List} \begin{lstlisting} -In []: a = [ 5, 2, 3, 1, 4] +In []: p = [ 2, 3, 5, 7] -In []: a[0]+a[1]+a[-1] -Out[]: 11 +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 = [ 5, 2, 3, 1, 4]} + \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, 1] +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 = [ 8, 6, 9, 9] -In []: c = a + b +In []: b = [ 11, 13, 17] +In []: c = p + b In []: c -Out[]: [5, 2, 3, 1, 4, 8, 6, 9, 9] +Out[]: [2, 3, 5, 7, 11, 13, 17] -In []: a.append(6) -In []: a -Out[]: [5, 2, 3, 1, 4, 6] +In []: p.append(11) +In []: p +Out[]: [ 2, 3, 5, 7, 11] \end{lstlisting} %\inctime{10} \end{frame} @@ -299,27 +301,40 @@ In []: t = [0.69, 0.90, 1.19, \begin{lstlisting} In []: tsq = [] +In []: len(l) +Out[]: 9 + +In []: len(t) +Out[]: 9 + In []: for time in t: ....: tsq.append(time*time) ....: ....: -\end{lstlisting} -Hit the ``ENTER'' key twice to come to the previous indentation level -\begin{lstlisting} -In []: print tsq -\end{lstlisting} -\kwrd{tsq} is the list of squares of \typ{t} values. -\end{frame} -\begin{frame}[fragile] -\frametitle{Plotting $L$ vs $T^2$ \ldots} -\begin{lstlisting} In []: plot(l, tsq) Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>] \end{lstlisting} -This gives the required plot. +This gives \kwrd{tsq} which is the list of squares of \typ{t} values. +\end{frame} + +\begin{frame}[fragile] + \frametitle{How to come out of the \texttt{for} loop?} + 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, len(tsq) + In []: plot(l, tsq) + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile] \begin{figure} -\includegraphics[width=2.2in]{data/L-TSq-limited.png} +\includegraphics[width=3.5in]{data/L-TSq-limited.png} \end{figure} \end{frame} @@ -353,7 +368,7 @@ $ cat pendulum.txt \begin{frame}[fragile] \frametitle{Plotting from \typ{pendulum.txt}} -Type the following in an editor. Save as \typ{pend\_pl.py} +Open a new script and type the following: \begin{lstlisting} l = [] t = [] @@ -365,15 +380,14 @@ tsq = [] for time in t: tsq.append(time*time) plot(l, tsq, '.') -show() \end{lstlisting} \end{frame} \begin{frame} \frametitle{Save and run} \begin{itemize} - \item Save as \typ{pend\_pl.py} - \item Run using \kwrd{\%run -i pend\_pl.py} + \item Save as pendulum\_plot.py. + \item Run using \kwrd{\%run -i pendulum\_plot.py} \end{itemize} \end{frame} @@ -452,7 +466,6 @@ tsq = [] for time in t: tsq.append(time*time) plot(l, tsq, '.') -show() \end{lstlisting} \end{frame} diff --git a/day1/session3.tex b/day1/session3.tex index 135bfc1..49e5773 100644 --- a/day1/session3.tex +++ b/day1/session3.tex @@ -79,7 +79,7 @@ \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 3} +\date[] {12 February, 2010\\Day 1, Session 3} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -319,7 +319,7 @@ science = {} \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 --git a/day1/session4.tex b/day1/session4.tex index 9195ff6..9cf0768 100644 --- a/day1/session4.tex +++ b/day1/session4.tex @@ -79,7 +79,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 4} +\date[] {13 February, 2010\\Day 2, Session 1} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -279,6 +279,21 @@ array([[11, 13], \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 @@ Out[]: array([-1., 8., -1.]) \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 --git a/day1/session5.tex b/day1/session5.tex index 1098b3e..4f51519 100644 --- a/day1/session5.tex +++ b/day1/session5.tex @@ -78,7 +78,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 5} +\date[] {12 February, 2010\\Day 1, Session 5} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -127,10 +127,7 @@ for line in open('pendulum.txt'): point = line.split() l.append(float(point[0])) t.append(float(point[1])) -tsq = [] -for time in t: - tsq.append(time*time) -plot(l, tsq, '.') +plot(l, t, '.') \end{lstlisting} \end{block} \end{columns} @@ -192,7 +189,7 @@ In []: plot(x, exp(x/10)*sin(x)) \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 --git a/day1/session6.tex b/day1/session6.tex index a5c1a2c..85ff042 100755 --- a/day1/session6.tex +++ b/day1/session6.tex @@ -78,7 +78,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {11 January, 2010\\Day 1, Session 6} +\date[] {13 February, 2010\\Day 2, Session 2} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |