day1/session2.tex
changeset 158 978108b0c02c
parent 153 dc0da25b788b
child 159 01f57cda252f
equal deleted inserted replaced
155:069a9aed1027 158:978108b0c02c
   199   \item \kwrd{'-'} - Lines
   199   \item \kwrd{'-'} - Lines
   200   \item \kwrd{'- -'} - Dashed lines
   200   \item \kwrd{'- -'} - Dashed lines
   201 \end{itemize}
   201 \end{itemize}
   202 \end{frame}
   202 \end{frame}
   203 
   203 
   204 
   204 \begin{frame}[fragile]
       
   205 \frametitle{Plotting \it{L} vs \it{T^2}}
       
   206 \begin{lstlisting}
       
   207 In []: TSq = []
       
   208 
       
   209 In []: for t in T:
       
   210  ....:     TSq.append(t*t)
       
   211 
       
   212 In []: plot(L, TSq, '.')
       
   213 Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>]
       
   214 \end{lstlisting}
       
   215 \end{frame}
       
   216 
       
   217 \begin{frame}{So what did we learn here??}
       
   218   \begin{itemize}
       
   219     \item lists
       
   220     \item \alert{\kwrd{for}}
       
   221   \end{itemize}
       
   222 \end{frame}
       
   223 
       
   224 \section{Lists}
       
   225 \begin{frame}[fragile]
       
   226   \frametitle{How to create and use lists?}
       
   227 \begin{lstlisting}
       
   228 In []: lst = [1,2,3,4] 
       
   229 
       
   230 In []: lst[0]+lst[1]+lst[-1]
       
   231 Out[]: 7
       
   232 \end{lstlisting}
       
   233 \end{frame}
       
   234 
       
   235 \begin{frame}[fragile]
       
   236   \frametitle{List: Slicing}
       
   237   \typ{list[initial:final:step]}
       
   238 \begin{lstlisting}
       
   239 In []: lst[1:3]  # A slice.
       
   240 Out[]: [2, 3]
       
   241 
       
   242 In []: lst[1:-1]
       
   243 Out[]: [2, 3]
       
   244 \end{lstlisting}
       
   245 \end{frame}
       
   246 
       
   247 \begin{frame}[fragile]
       
   248   \frametitle{List methods}
       
   249 \begin{lstlisting}
       
   250 In []: lst.append([6,7])
       
   251 In []: lst
       
   252 Out[]: [1, 2, 3, 4, 5, [6, 7]]
       
   253 \end{lstlisting}
       
   254 %\inctime{10}
       
   255 \end{frame}
       
   256 
       
   257 \begin{frame}[fragile]
       
   258 \frametitle{\typ{for}}
       
   259 Used to iterate over lists\\ Let us look at another example.
       
   260 \begin{lstlisting}
       
   261 In []: lst = [1,2,3,4,5,6]
       
   262 In []: for num in lst:
       
   263  ....:     print num, num*num
       
   264  ....:    
       
   265 1 1
       
   266 2 4
       
   267 3 9
       
   268 4 16
       
   269 5 25
       
   270 6 36
       
   271 \end{lstlisting}
       
   272 \end{frame}
   205 
   273 
   206 \section{File Handling}
   274 \section{File Handling}
   207 \begin{frame}[fragile]
   275 \begin{frame}[fragile]
   208     \frametitle{File and \kwrd{for}}
   276     \frametitle{File and \kwrd{for}}
   209 \begin{lstlisting}
   277 \begin{lstlisting}
   238 \inctime{5}
   306 \inctime{5}
   239 \end{frame}
   307 \end{frame}
   240 
   308 
   241 \section{Plotting points}
   309 \section{Plotting points}
   242 
   310 
   243 \section{Lists}
       
   244 
       
   245 \begin{frame}[fragile]
       
   246   \frametitle{List creation and indexing}
       
   247 \begin{lstlisting}
       
   248 In []: lst = [1,2,3,4] 
       
   249 
       
   250 In []: lst[0]+lst[1]+lst[-1]
       
   251 Out[]: 7
       
   252 \end{lstlisting}
       
   253 \begin{itemize}
       
   254   \item Indices start with ?
       
   255   \item Negative indices indicate ?
       
   256   \end{itemize}
       
   257 \end{frame}
       
   258 
       
   259 \begin{frame}[fragile]
       
   260   \frametitle{List: slices}
       
   261   \typ{list[initial:final:step]}
       
   262 \begin{lstlisting}
       
   263 In []: lst[1:3]  # A slice.
       
   264 Out[]: [2, 3]
       
   265 
       
   266 In []: lst[1:-1]
       
   267 Out[]: [2, 3]
       
   268 \end{lstlisting}
       
   269 \end{frame}
       
   270 
       
   271 \begin{frame}[fragile]
       
   272   \frametitle{List methods}
       
   273 \begin{lstlisting}
       
   274 In []: lst.append([6,7])
       
   275 In []: lst
       
   276 Out[]: [1, 2, 3, 4, 5, [6, 7]]
       
   277 \end{lstlisting}
       
   278 \inctime{10}
       
   279 \end{frame}
       
   280 
   311 
   281 \end{document}
   312 \end{document}