day1/cheatsheet3.tex
changeset 295 39d7c4e14585
parent 284 3c191accbb32
child 330 46533051b9d3
equal deleted inserted replaced
289:884d42eff66d 295:39d7c4e14585
     1 \documentclass[12pt]{article}
     1 \documentclass[12pt]{article}
     2 \title{Interactive Plotting}
     2 \title{Interactive Plotting}
     3 \author{FOSSEE}
     3 \author{FOSSEE}
       
     4 
       
     5 \usepackage{listings}
       
     6 \lstset{language=Python,
       
     7     basicstyle=\ttfamily,
       
     8   commentstyle=\itshape\bfseries,
       
     9   showstringspaces=false,
       
    10 }
       
    11 \newcommand{\typ}[1]{\lstinline{#1}}
       
    12 \usepackage[english]{babel}
       
    13 \usepackage[latin1]{inputenc}
       
    14 \usepackage{times}
       
    15 \usepackage[T1]{fontenc}
       
    16 \usepackage{ae,aecompl}
       
    17 \usepackage{mathpazo,courier,euler}
       
    18 \usepackage[scaled=.95]{helvet}
       
    19 
     4 \begin{document}
    20 \begin{document}
     5 \date{}
    21 \date{}
     6 \vspace{-1in}
    22 \vspace{-1in}
     7 \begin{center}
    23 \begin{center}
     8 \LARGE{Statistics and Least square fit}\\
    24 \LARGE{Statistics and Least square fit}\\
     9 \large{FOSSEE}
    25 \large{FOSSEE}
    10 \end{center}
    26 \end{center}
    11 \section{Statistics}
    27 \section{Statistics}
    12 Dictionary
    28 Dictionary
    13 \begin{verbatim}
    29 \begin{lstlisting}
    14 In [1]: d = {"Hitchhiker's guide" : 42, 
    30 In []: d = {"Hitchhiker's guide" : 42, 
    15   ....:      "Terminator" : "I'll be back"} #Creation
    31  ....:      "Terminator" : "I'll be back"} #Creation
    16 In [2]: d["Hitchhiker's guide"] # Accessing a value with key
    32 In []: d["Hitchhiker's guide"] # Accessing a value with key
    17 In [3]: "Hitchhiker's guide" in d #Checking for a key
    33 In []: "Hitchhiker's guide" in d #Checking for a key
    18 In [4]: d.keys() # Obtaining List of Keys
    34 In []: d.keys() # Obtaining List of Keys
    19 In [5]: d.values() # Obtaining List of Values
    35 In []: d.values() # Obtaining List of Values
    20 \end{verbatim}
    36 \end{lstlisting}
    21 Iterating through List indices
    37 Iterating through List indices
    22 \begin{verbatim}
    38 \begin{lstlisting}
    23 In [1]: names = ["Guido","Alex", "Tim"]
    39 In []: names = ["Guido","Alex", "Tim"]
    24 In [2]: for i, name in enumerate(names):
    40 In []: for i, name in enumerate(names):
    25    ...:     print i, name
    41   ...:     print i, name
    26 \end{verbatim}
    42 \end{lstlisting}
       
    43 Computing Mean value of `\texttt{g}'
       
    44 \begin{lstlisting}
       
    45 In []: G = []
       
    46 In []: for line in open('pendulum.txt'):
       
    47   ....     points = line.split()
       
    48   ....     l = float(points[0])
       
    49   ....     t = float(points[1])
       
    50   ....     g = 4 * pi * pi * l / t * t
       
    51   ....     G.append(g)
       
    52 \end{lstlisting}
       
    53 sum() and len() functions
       
    54 \begin{lstlisting}
       
    55   total = 0
       
    56   for g in G:
       
    57     total += g
       
    58   mean_g = total / len(g)
    27 
    59 
    28 \begin{verbatim}
    60   mean_g = sum(G) / len(G)
    29 In [1]: score = int(score_str) if score_str != 'AA' else 0
    61   mean_g = mean(G)
    30 \end{verbatim}
    62 \end{lstlisting}
       
    63 \newpage
       
    64 Ternary Operator
       
    65 \begin{lstlisting}
       
    66 In []: score = int(score_str) if score_str != 'AA' else 0
       
    67 \end{lstlisting}
    31 Drawing Pie Charts
    68 Drawing Pie Charts
    32 \begin{verbatim}
    69 \begin{lstlisting}
    33 In [1]: pie(science.values(), labels=science.keys())
    70 In []: pie(science.values(), labels=science.keys())
    34 \end{verbatim}
    71 \end{lstlisting}
    35 sum() and len() functions
       
    36 \begin{verbatim}
       
    37 In [1]: mean = sum(math_scores) / len(math_scores)
       
    38 \end{verbatim}
       
    39 Numpy Arrays
    72 Numpy Arrays
    40 \begin{verbatim}
    73 \begin{lstlisting}
    41 In [1]: a = array([1, 2, 3]) #Creating
    74 In []: a = array([1, 2, 3]) #Creating
    42 In [2]: b = array([4, 5, 6])
    75 In []: b = array([4, 5, 6])
    43 In [3]: a + b #Sum; Element-wise
    76 In []: a + b #Sum; Element-wise
    44 \end{verbatim}
    77 \end{lstlisting}
    45 Numpy statistical operations 
    78 Numpy statistical operations 
    46 \begin{verbatim}
    79 \begin{lstlisting}
    47 In [1]: mean(math_scores)
    80 In []: mean(math_scores)
    48 In [2]: median(math_scores)
    81 In []: median(math_scores)
    49 In [3]: stats.mode(math_scores)
    82 In []: std(math_scores)
    50 In [4]: std(math_scores)
    83 \end{lstlisting}
    51 \end{verbatim}
       
    52 Generating Van der Monde matrix
       
    53 \begin{verbatim}
       
    54 In [1]: A = vander(L, 2)
       
    55 \end{verbatim}
       
    56 Getting a Least Squares Fit curve
       
    57 \begin{verbatim}
       
    58 In [1]: coef, res, r, s = lstsq(A,TSq)
       
    59 In [2]: Tline = coef[0]*L + coef[1]
       
    60 In [3]: plot(L, Tline)
       
    61 \end{verbatim}
       
    62 \end{document}
    84 \end{document}
    63