day2/handout.tex
changeset 78 ec1346330649
parent 72 1c1d6aaa2be3
--- a/day2/handout.tex	Fri Oct 09 11:13:37 2009 +0530
+++ b/day2/handout.tex	Fri Oct 09 11:52:51 2009 +0530
@@ -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 @@
 
 >>> 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 @@
 >>>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 @@
        [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 @@
 42
 \end{verbatim}
 
-\subsection{Problem Set}
+\subsubsection{Problem Set}
 \begin{verbatim}
     >>> from scipy import misc
     >>> A=misc.imread(name)
@@ -112,6 +120,7 @@
 \end{enumerate}
 
 \subsection{2D Plotting}
+\subsubsection{Basic 2D Plotting}
 \begin{verbatim}
 $ ipython -pylab
 >>> x = linspace(0, 2*pi, 1000)
@@ -122,7 +131,9 @@
 >>> 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 @@
 >>> 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 @@
              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 @@
 >>> 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 @@
 
 \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 @@
 \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