day1/session3.tex
changeset 170 36ed5cdf5fde
parent 167 5f13be28532d
child 174 a43832c1edc2
equal deleted inserted replaced
169:bb3739afce10 170:36ed5cdf5fde
   309   \frametitle{Dictionary - Building parsed data...}
   309   \frametitle{Dictionary - Building parsed data...}
   310   \begin{itemize}
   310   \begin{itemize}
   311     \item In this problem let the value of a \emph{key} be another dictionary.
   311     \item In this problem let the value of a \emph{key} be another dictionary.
   312     \item This dictionary contains:
   312     \item This dictionary contains:
   313     \begin{itemize}
   313     \begin{itemize}
   314       \item 'marks': A \emph{list} of NumPy arrays
   314       \item 'marks': A \emph{List} of \emph{Lists} containing all marks
   315       \item 'total': Total marks of each student
   315       \item 'total': A \emph{List} of total marks of each student
   316       \item 'P': Number of passes
   316       \item 'P': Number of passes
   317       \item 'F': Number of failures
   317       \item 'F': Number of failures
   318       \item 'W': Number of withdrawls
   318       \item 'W': Number of withdrawls
   319     \end{itemize}
   319     \end{itemize}
   320   \end{itemize}
   320   \end{itemize}
   360 total = 0 if score_str == 'AA'
   360 total = 0 if score_str == 'AA'
   361     or score_str == 'AAA'
   361     or score_str == 'AAA'
   362     or score_str == ''
   362     or score_str == ''
   363     else int(fields[8])
   363     else int(fields[8])
   364 data[fields[0]]['total'].append(total)
   364 data[fields[0]]['total'].append(total)
   365 
   365   \end{lstlisting}
       
   366 \end{frame}
       
   367 
       
   368 \begin{frame}[fragile]
       
   369   \frametitle{Dictionary - Building parsed data \ldots}
       
   370   \begin{lstlisting}
   366 pfw_key = fields[9]
   371 pfw_key = fields[9]
   367     or fields[10]
   372     or fields[10]
   368     or 'F'
   373     or 'F'
   369 data[fields[0]][pfw_key] += 1
   374 data[fields[0]][pfw_key] += 1
   370   \end{lstlisting}
   375   \end{lstlisting}
   371 \end{frame}
   376 \end{frame}
   372 
   377 
   373 \begin{frame}[fragile]
   378 \begin{frame}[fragile]
   374   \frametitle{Dictionary - Building parsed data \ldots}
   379   \frametitle{NumPy arrays}
   375   \begin{lstlisting}
   380   \centerline{\alert{But I lied!?!?!?}}
   376 pfw_key = fields[9]
   381 \end{frame}
   377     or fields[10]
   382 
   378     or 'F'
   383 \begin{frame}[fragile]
   379 data[fields[0]][pfw_key] += 1
   384   \frametitle{Calculations}
       
   385   \begin{lstlisting}
       
   386 for k in data:
       
   387     data[k]['marks'] = array(
       
   388         data[k]['marks'])
       
   389     data[k]['total'] = array(
       
   390         data[k]['total'])
   380   \end{lstlisting}
   391   \end{lstlisting}
   381 \end{frame}
   392 \end{frame}
   382 
   393 
   383 \begin{frame}[fragile]
   394 \begin{frame}[fragile]
   384   \frametitle{Calculations}
   395   \frametitle{Calculations}
   385   \small
   396   \small
   386   \begin{lstlisting}
   397   \begin{lstlisting}
   387 for k in data:
       
   388     data[k]['marks'] = array(data[k]['marks'])
       
   389     data[k]['total'] = array(data[k]['total'])
       
   390 
       
   391     data[k]['avg'] = average(
   398     data[k]['avg'] = average(
   392         data[k]['total'])
   399         data[k]['total'])
   393     marks = data[k]['marks']
   400     marks = data[k]['marks']
   394     sub_avg = average(marks, axis=1)
   401     sub_avg = average(marks, axis=1)
   395     sub_std = sqrt(sum(square(
   402     sub_std = sqrt(sum(square(
   406    \item Dictionaries
   413    \item Dictionaries
   407    \item Slicing lists
   414    \item Slicing lists
   408    \item New type of conditional
   415    \item New type of conditional
   409    \item NumPy arrays
   416    \item NumPy arrays
   410    \item Slicing NumPy arrays
   417    \item Slicing NumPy arrays
   411    \item NumPy array operations - square, average, sqrt
   418    \item NumPy array functions - square, average, sqrt
   412   \end{itemize}
   419   \end{itemize}
   413 \end{frame}
   420 \end{frame}
   414 
   421 
   415 \end{document}
   422 \end{document}