summaryrefslogtreecommitdiff
path: root/day2/handout.tex
diff options
context:
space:
mode:
authorPuneeth Chaganti2009-10-09 11:52:51 +0530
committerPuneeth Chaganti2009-10-09 11:52:51 +0530
commita84515c6184cbc6231c5473f8985670805d747af (patch)
tree5d659abf68dee33b54b0f95f8bd6f46abc1fae99 /day2/handout.tex
parenteeaeb0b0f0dbd5cd3bf3001cac87ba74eb7fb8b2 (diff)
downloadworkshops-a84515c6184cbc6231c5473f8985670805d747af.tar.gz
workshops-a84515c6184cbc6231c5473f8985670805d747af.tar.bz2
workshops-a84515c6184cbc6231c5473f8985670805d747af.zip
Minor edits to Day2 handout.
Diffstat (limited to 'day2/handout.tex')
-rw-r--r--day2/handout.tex37
1 files changed, 29 insertions, 8 deletions
diff --git a/day2/handout.tex b/day2/handout.tex
index d7df544..7d56088 100644
--- a/day2/handout.tex
+++ b/day2/handout.tex
@@ -7,6 +7,7 @@
\section{Matrices and Arrays \& 2D Plotting}
\subsection{Matrices and Arrays}
+\subsubsection{Basic Numpy}
\begin{verbatim}
# Simple array math example
>>> import numpy as np
@@ -54,7 +55,10 @@ array([10,11,12,-1])
>>> np.greater(a,4)
>>> np.sqrt(a)
+\end{verbatim}
+\subsubsection{Array Creation}
+\begin{verbatim}
>>> np.array([2,3,4])
array([2, 3, 4])
@@ -69,7 +73,9 @@ array([[ 1., 1.],
>>>np.ones_like(a)
array([[1, 1, 1],
[1, 1, 1]])
-
+\end{verbatim}
+\subsubsection{Slicing, Striding Arrays}
+\begin{verbatim}
>>> a = np.array([[1,2,3], [4,5,6],
[7,8,9]])
>>> a[0,1:3]
@@ -87,7 +93,9 @@ array([[1, 3],
[7, 9]])
# Slices are references to the
# same memory!
-
+\end{verbatim}
+\subsubsection{Random Numbers}
+\begin{verbatim}
>>> np.random.rand(3,2)
array([[ 0.96276665, 0.77174861],
[ 0.35138557, 0.61462271],
@@ -96,7 +104,7 @@ array([[ 0.96276665, 0.77174861],
42
\end{verbatim}
-\subsection{Problem Set}
+\subsubsection{Problem Set}
\begin{verbatim}
>>> from scipy import misc
>>> A=misc.imread(name)
@@ -112,6 +120,7 @@ array([[ 0.96276665, 0.77174861],
\end{enumerate}
\subsection{2D Plotting}
+\subsubsection{Basic 2D Plotting}
\begin{verbatim}
$ ipython -pylab
>>> x = linspace(0, 2*pi, 1000)
@@ -122,7 +131,9 @@ $ ipython -pylab
>>> ylabel(r'sin($\chi$)', color='r')
>>> title('Simple figure', fontsize=20)
>>> savefig('/tmp/test.eps')
-
+\end{verbatim}
+\subsubsection{Tweaking plots}
+\begin{verbatim}
# Set properties of objects:
>>> l, = plot(x, sin(x))
# Why "l,"?
@@ -132,7 +143,10 @@ $ ipython -pylab
>>> setp(l) # Print properties.
>>> clf() # Clear figure.
>>> close() # Close figure.
+\end{verbatim}
+\subsubsection{Working with text}
+\begin{verbatim}
>>> w = arange(-2,2,.1)
>>> plot(w,exp(-(w*w))*cos)
>>> ylabel('$f(\omega)$')
@@ -144,7 +158,10 @@ $ ipython -pylab
arrowprops=dict(
facecolor='black',
shrink=0.05))
+\end{verbatim}
+\subsubsection{Legends}
+\begin{verbatim}
>>> x = linspace(0, 2*np.pi, 1000)
>>> plot(x, cos(5*x), 'r--',
label='cosine')
@@ -153,7 +170,10 @@ $ ipython -pylab
>>> legend()
# Or use:
>>> legend(['cosine', 'sine'])
+\end{verbatim}
+\subsubsection{Multiple figures}
+\begin{verbatim}
>>> figure(1)
>>> plot(x, sin(x))
>>> figure(2)
@@ -163,7 +183,7 @@ $ ipython -pylab
\end{verbatim}
-\subsection{Problem Set}
+\subsubsection{Problem Set}
\begin{enumerate}
\item Write a function that plots any regular n-gon given n.
\item Consider the logistic map, $f(x) = kx(1-x)$, plot it for
@@ -187,11 +207,12 @@ $ ipython -pylab
\begin{verbatim}
>>> a = np.arange(4)
>>> b = np.arange(5)
->>> a+b
+>>> a+b #Does this work?
>>> a+3
>>> c=np.array([3])
->>> a+c
->>> b+c
+>>> a+c #Works!
+>>> b+c #But how?
+>>> a.shape, b.shape, c.shape
>>> a = np.arange(4)
>>> a+3