diff options
Diffstat (limited to 'day2')
-rw-r--r-- | day2/handout.tex | 37 | ||||
-rw-r--r-- | day2/session1.tex | 13 | ||||
-rw-r--r-- | day2/session2.tex | 21 | ||||
-rw-r--r-- | day2/session3.tex | 2 | ||||
-rw-r--r-- | day2/tda.tex | 13 |
5 files changed, 62 insertions, 24 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 diff --git a/day2/session1.tex b/day2/session1.tex index 1d80bd4..357f18c 100644 --- a/day2/session1.tex +++ b/day2/session1.tex @@ -134,10 +134,8 @@ \item Why? \item What: \begin{itemize} - \item An efficient and powerful array type for various common data - types - \item Abstracts out the most commonly used standard operations on - arrays + \item An efficient and powerful array type for various common data types + \item Abstracts out the most commonly used standard operations on arrays \end{itemize} \end{itemize} \end{frame} @@ -803,4 +801,11 @@ title('triangular head; scale '\ \end{columns} \inctime{20} \end{frame} +\begin{frame}{Summary} + \begin{itemize} + \item Basics of Numpy. + \item Array operations. + \item Plotting in 2D. + \end{itemize} +\end{frame} \end{document} diff --git a/day2/session2.tex b/day2/session2.tex index 9a02146..3f0184d 100644 --- a/day2/session2.tex +++ b/day2/session2.tex @@ -124,11 +124,12 @@ \begin{lstlisting} >>> 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 \end{lstlisting} \begin{itemize} \item Enter Broadcasting! @@ -426,8 +427,18 @@ Make a plot of $\frac{dx}{dt}$ vs. $x$. \inctime{30} \end{frame} - - +\begin{frame}{Summary} + \begin{itemize} + \item Advanced NumPy + \item SciPy + \begin{itemize} + \item Linear Algebra + \item Integration + \item Interpolation + \item Signal and Image processing + \end{itemize} + \end{itemize} +\end{frame} \end{document} - Numpy arrays (30 mins) diff --git a/day2/session3.tex b/day2/session3.tex index 8154c74..b1221e5 100644 --- a/day2/session3.tex +++ b/day2/session3.tex @@ -194,7 +194,7 @@ \section{Tools at your disposal} -\subsection{Mayavi2.0} +\subsection{Mayavi2} \begin{frame} \frametitle{Introduction to Mayavi} diff --git a/day2/tda.tex b/day2/tda.tex index ae39f4a..664eed3 100644 --- a/day2/tda.tex +++ b/day2/tda.tex @@ -261,7 +261,7 @@ def test_function_ignore_cases_words(): \begin{frame}[fragile] \frametitle{Exercise} - Based on Euclid's theorem: + Based on Euclid's algorithm: $gcd(a,b)=gcd(b,b\%a)$\\ gcd function can be written as: \begin{lstlisting} @@ -269,14 +269,15 @@ def test_function_ignore_cases_words(): if a%b == 0: return b return gcd(b, a%b) \end{lstlisting} + \vspace*{-0.15in} \begin{block}{Task} - For given gcd implementation write - at least two tests. - \end{block} - \begin{block}{Task} - Write a non recursive implementation + \begin{itemize} + \item Write at least + two tests for above mentioned function. + \item Write a non recursive implementation of gcd(), and test it using already written tests. + \end{itemize} \end{block} \inctime{15} |