summaryrefslogtreecommitdiff
path: root/day1/cheatsheet3.tex
blob: df00c67cb4d9312a62ba39a9e424ac1ec4413d73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
\documentclass[12pt]{article}
\title{Interactive Plotting}
\author{FOSSEE}
\begin{document}
\date{}
\vspace{-1in}
\begin{center}
\LARGE{Statistics and Least square fit}\\
\large{FOSSEE}
\end{center}
\section{Statistics}
Dictionary
\begin{verbatim}
In [1]: d = {"Hitchhiker's guide" : 42, 
  ....:      "Terminator" : "I'll be back"} #Creation
In [2]: d["Hitchhiker's guide"] # Accessing a value with key
In [3]: "Hitchhiker's guide" in d #Checking for a key
In [4]: d.keys() # Obtaining List of Keys
In [5]: d.values() # Obtaining List of Values
\end{verbatim}
Iterating through List indices
\begin{verbatim}
In [1]: names = ["Guido","Alex", "Tim"]
In [2]: for i, name in enumerate(names):
   ...:     print i, name
\end{verbatim}

\begin{verbatim}
In [1]: score = int(score_str) if score_str != 'AA' else 0
\end{verbatim}
Drawing Pie Charts
\begin{verbatim}
In [1]: pie(science.values(), labels=science.keys())
\end{verbatim}
sum() and len() functions
\begin{verbatim}
In [1]: mean = sum(math_scores) / len(math_scores)
\end{verbatim}
Numpy Arrays
\begin{verbatim}
In [1]: a = array([1, 2, 3]) #Creating
In [2]: b = array([4, 5, 6])
In [3]: a + b #Sum; Element-wise
\end{verbatim}
Numpy statistical operations 
\begin{verbatim}
In [1]: mean(math_scores)
In [2]: median(math_scores)
In [3]: stats.mode(math_scores)
In [4]: std(math_scores)
\end{verbatim}
Generating Van der Monde matrix
\begin{verbatim}
In [1]: A = vander(L, 2)
\end{verbatim}
Getting a Least Squares Fit curve
\begin{verbatim}
In [1]: coef, res, r, s = lstsq(A,TSq)
In [2]: Tline = coef[0]*L + coef[1]
In [3]: plot(L, Tline)
\end{verbatim}
\end{document}