diff options
author | Puneeth Chaganti | 2009-11-06 13:53:20 +0530 |
---|---|---|
committer | Puneeth Chaganti | 2009-11-06 13:53:20 +0530 |
commit | 9715e79a11b73b60a2cc9e83658781a502cb0803 (patch) | |
tree | ac7b20446ead23b869b7beabdf51dbc7d357bcaf | |
parent | b01fb222c5b6f1002e724e682ec1b58aa97e5dc5 (diff) | |
download | workshops-more-scipy-9715e79a11b73b60a2cc9e83658781a502cb0803.tar.gz workshops-more-scipy-9715e79a11b73b60a2cc9e83658781a502cb0803.tar.bz2 workshops-more-scipy-9715e79a11b73b60a2cc9e83658781a502cb0803.zip |
Added Cheatsheets for day1.
-rw-r--r-- | day1/cheatsheet2.tex | 37 | ||||
-rw-r--r-- | day1/cheatsheet3.tex | 63 | ||||
-rw-r--r-- | day1/cheatsheet4.tex | 47 | ||||
-rw-r--r-- | day1/cheatsheet5.tex | 49 |
4 files changed, 196 insertions, 0 deletions
diff --git a/day1/cheatsheet2.tex b/day1/cheatsheet2.tex new file mode 100644 index 0000000..65ef411 --- /dev/null +++ b/day1/cheatsheet2.tex @@ -0,0 +1,37 @@ +\documentclass[12pt]{article} +%\title{Plotting Data} +%\author{FOSSEE} +\begin{document} +\date{} +\vspace{-1in} +\begin{center} +\LARGE{Plotting Data}\\ +\large{FOSSEE} +\end{center} +\section{Scripts} +IPython History +\begin{verbatim} +In [1]: %hist +In [2]: %hist -n +\end{verbatim} + +Running a Script +\begin{verbatim} +In [3]: %run script_name.py +\end{verbatim} + +\section{Plotting from Data files} +\begin{verbatim} +In [1]: L = [] #Empty List +In [2]: T = [] +In [3]: for line in open('pendulum.txt'): # Opening & Reading files + ....: points = line.split() # Splitting a string + ....: L.append(float(points[0])) # Appending to a list + ....: T.append(float(points[1])) +In [4]: TSq = [] +In [5]: for t in T: #Iterating through lists + ....: TSq.append(t*t) +In [6]: plot(L, TSq, '.') # Plotting points +\end{verbatim} +\end{document} + diff --git a/day1/cheatsheet3.tex b/day1/cheatsheet3.tex new file mode 100644 index 0000000..df00c67 --- /dev/null +++ b/day1/cheatsheet3.tex @@ -0,0 +1,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} + diff --git a/day1/cheatsheet4.tex b/day1/cheatsheet4.tex new file mode 100644 index 0000000..54ae95d --- /dev/null +++ b/day1/cheatsheet4.tex @@ -0,0 +1,47 @@ +\documentclass[12pt]{article} +\title{Matrices and Solution of Equations} +\author{FOSSEE} +\begin{document} +\date{} +\vspace{-1in} +\begin{center} +\LARGE{Matrices and Solution of Equations}\\ +\large{FOSSEE} +\end{center} +\section{Matrices} +Inputting a Matrix +\begin{verbatim} +In [1]: A = matrix([[1, 2, 3],[4, 5, 6]]) +\end{verbatim} +Matrix Operations +\begin{verbatim} +In [1]: A.T # Transpose +In [2]: sum(A) # Sum of all elements +In [3]: A+B # Addition +In [1]: A*B # Product +In [1]: inv(A) # Inverse +In [1]: det(A) # Determinant +\end{verbatim} + +Eigen Values and Eigen Vectors +\begin{verbatim} +In [1]: eig(A) #Eigen Values and Vectors +In [2]: eigvals(A) #Eigen Values +\end{verbatim} +Norm +\begin{verbatim} +In [1]: norm(A) +\end{verbatim} +Single Value Decomposition +\begin{verbatim} +In [1]: svd(A) +\end{verbatim} +Solving a set of equations +\begin{verbatim} +In [1]: A = matrix([...]) # Input Equation Coefficient Matrix +In [2]: b = matrix([...]) # Equation Target Values +In [3]: x = solve(A, b) +In [4]: Ax = A*x +\end{verbatim} +\end{document} + diff --git a/day1/cheatsheet5.tex b/day1/cheatsheet5.tex new file mode 100644 index 0000000..0a0f600 --- /dev/null +++ b/day1/cheatsheet5.tex @@ -0,0 +1,49 @@ +\documentclass[12pt]{article} +\title{Matrices and Solution of Equations} +\author{FOSSEE} +\begin{document} +\date{} +\vspace{-1in} +\begin{center} +\LARGE{Interpolation, Differentiation and Integration}\\ +\large{FOSSEE} +\end{center} +\section{} +Loading a data file +\begin{verbatim} +In [2]: x, y = loadtxt('points.txt', unpack = True) +#load data file directly into Arrays. +\end{verbatim} +\section{} +Interploate +\begin{verbatim} +In []: from scipy.interpolate import splrep +In []: tck = splrep(x,y) #get spline curve representation for x,y. +In []: from scipy.interpolate import splev +#To evaluate spline and it's derivatives. +In []: Xnew = arange(0.01,3,0.02) +#missing set of points +In []: Ynew = splev(Xnew, tck) +#Value of function at Xnew +In []: plot(Xnew, Ynew) +\end{verbatim} + +\section{Differentiation} +Taylor series - finite difference approximations +$f(x+h)=f(x)+hf^{'}(x)$ Forward +\begin{verbatim} +In []: x = linspace(0, 2*pi, 100) +In []: y = sin(x) +In []: deltax = x[1] - x[0] +In []: fD = (y[1:] - y[:-1]) / deltax +#fD is the required forward difference +\end{verbatim} + +\section{Quadrature} +$\int_0^1(sin(x) + x^2)$ +In []: def f(x): + return sin(x)+x**2 +In []: from scipy.integrate import quad +In []: quad(f, 0, 1) +\end{document} + |