day1/session3.tex
changeset 337 56aa2efbf7d9
parent 330 46533051b9d3
child 339 8ac5fe07810f
equal deleted inserted replaced
335:45bcdc34bf73 337:56aa2efbf7d9
   145 In []: G = []
   145 In []: G = []
   146 In []: for line in open('pendulum.txt'):
   146 In []: for line in open('pendulum.txt'):
   147   ....     point = line.split()
   147   ....     point = line.split()
   148   ....     l = float(point[0])
   148   ....     l = float(point[0])
   149   ....     t = float(point[1])
   149   ....     t = float(point[1])
   150   ....     g = 4 * pi * pi * l / t * t
   150   ....     g = 4 * pi * pi * l / (t * t)
   151   ....     G.append(g)
   151   ....     G.append(g)
   152   \end{lstlisting}
   152   \end{lstlisting}
   153 \end{frame}
   153 \end{frame}
   154 
   154 
   155 \begin{frame}
   155 \begin{frame}
   164   \begin{lstlisting}
   164   \begin{lstlisting}
   165 total = 0
   165 total = 0
   166 for g in G:
   166 for g in G:
   167     total += g
   167     total += g
   168 
   168 
   169 g_mean = total / len(g)
   169 g_mean = total / len(G)
   170 print "Mean: ", g_mean
   170 print 'Mean: ', g_mean
   171   \end{lstlisting}
   171   \end{lstlisting}
   172 \end{frame}
   172 \end{frame}
   173 
   173 
   174 \begin{frame}[fragile]
   174 \begin{frame}[fragile]
   175   \frametitle{Mean ``g''}
   175   \frametitle{Mean ``g''}
   176   \begin{lstlisting}
   176   \begin{lstlisting}
   177 g_mean = sum(G) / len(G)
   177 g_mean = sum(G) / len(G)
   178 print "Mean: ", g_mean
   178 print 'Mean: ', g_mean
   179   \end{lstlisting}
   179   \end{lstlisting}
   180 \end{frame}
   180 \end{frame}
   181 
   181 
   182 \begin{frame}[fragile]
   182 \begin{frame}[fragile]
   183   \frametitle{Mean ``g''}
   183   \frametitle{Mean ``g''}
   184   \begin{lstlisting}
   184   \begin{lstlisting}
   185 g_mean = mean(G)
   185 g_mean = mean(G)
   186 print "Mean: ", g_mean
   186 print 'Mean: ', g_mean
   187   \end{lstlisting}
   187   \end{lstlisting}
   188   \inctime{10}
   188   \inctime{10}
   189 \end{frame}
   189 \end{frame}
   190 
   190 
   191 \section{Processing voluminous data}
   191 \section{Processing voluminous data}
   275 \end{frame}
   275 \end{frame}
   276 
   276 
   277 \begin{frame}[fragile]
   277 \begin{frame}[fragile]
   278   \frametitle{Dictionaries \ldots}
   278   \frametitle{Dictionaries \ldots}
   279   \begin{lstlisting}
   279   \begin{lstlisting}
   280 In []: d = {"jpg" : "image file",
   280 In []: d = {'jpg' : 'image file',
   281       "txt" : "text file", 
   281       'txt' : 'text file', 
   282       "py" : "python code"}
   282       'py' : 'python code'}
   283 
   283 
   284 In []: d["txt"]
   284 In []: d['txt']
   285 Out[]: 'text file'
   285 Out[]: 'text file'
   286   \end{lstlisting}
   286   \end{lstlisting}
   287 \end{frame}
   287 \end{frame}
   288 
   288 
   289 \begin{frame}[fragile]
   289 \begin{frame}[fragile]
   290   \frametitle{Dictionaries \ldots}
   290   \frametitle{Dictionaries \ldots}
   291   \begin{lstlisting}
   291   \begin{lstlisting}
   292 In []: "py" in d
   292 In []: 'py' in d
   293 Out[]: True
   293 Out[]: True
   294 
   294 
   295 In []: "cpp" in d
   295 In []: 'cpp' in d
   296 Out[]: False
   296 Out[]: False
   297   \end{lstlisting}
   297   \end{lstlisting}
   298 \end{frame}
   298 \end{frame}
   299 
   299 
   300 \begin{frame}[fragile]
   300 \begin{frame}[fragile]
   415 \end{frame}
   415 \end{frame}
   416 
   416 
   417 \begin{frame}[fragile]
   417 \begin{frame}[fragile]
   418   \frametitle{Obtaining statistics}
   418   \frametitle{Obtaining statistics}
   419   \begin{lstlisting}
   419   \begin{lstlisting}
   420 print "Mean: ", mean(math_scores)
   420 print 'Mean: ', mean(math_scores)
   421 
   421 
   422 print "Median: ", median(math_scores)
   422 print 'Median: ', median(math_scores)
   423 
   423 
   424 print "Standard Deviation: ",
   424 print 'Standard Deviation: ',
   425               std(math_scores)
   425               std(math_scores)
   426   \end{lstlisting}
   426   \end{lstlisting}
   427   \inctime{10}
   427   \inctime{10}
   428 \end{frame}
   428 \end{frame}
   429 
   429 
   430 \begin{frame}[fragile]
   430 \begin{frame}[fragile]
   431   \frametitle{Obtaining statistics: efficiently!}
   431   \frametitle{Obtaining statistics: efficiently!}
   432   \begin{lstlisting}
   432   \begin{lstlisting}
   433 math_array = array(math_scores)
   433 math_array = array(math_scores)
   434 
   434 
   435 print "Mean: ", mean(math_array)
   435 print 'Mean: ', mean(math_array)
   436 
   436 
   437 print "Median: ", median(math_array)
   437 print 'Median: ', median(math_array)
   438 
   438 
   439 print "Standard Deviation: ",
   439 print 'Standard Deviation: ',
   440               std(math_array)
   440               std(math_array)
   441   \end{lstlisting}
   441   \end{lstlisting}
   442   \inctime{5}
   442   \inctime{5}
   443 \end{frame}
   443 \end{frame}
   444 
   444