diff options
author | Santosh G. Vattam | 2009-10-05 17:52:05 +0530 |
---|---|---|
committer | Santosh G. Vattam | 2009-10-05 17:52:05 +0530 |
commit | d3d35b62ed22c540598eddc21274b9152db28dea (patch) | |
tree | dddec33bbf4d1d524556100cd7ce0d2d98d4aaf3 /day2/session1.tex | |
parent | cd4d0cda610502d352094e6e515517b239a8ef63 (diff) | |
parent | b013b817d46da1516179e802dffd6f8dba73474a (diff) | |
download | workshops-more-scipy-d3d35b62ed22c540598eddc21274b9152db28dea.tar.gz workshops-more-scipy-d3d35b62ed22c540598eddc21274b9152db28dea.tar.bz2 workshops-more-scipy-d3d35b62ed22c540598eddc21274b9152db28dea.zip |
Branches merged.
Diffstat (limited to 'day2/session1.tex')
-rw-r--r-- | day2/session1.tex | 210 |
1 files changed, 117 insertions, 93 deletions
diff --git a/day2/session1.tex b/day2/session1.tex index 91fc3d6..47a6a76 100644 --- a/day2/session1.tex +++ b/day2/session1.tex @@ -51,7 +51,7 @@ \setcounter{time}{0} \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} -\newcommand{\typ}[1]{\texttt{#1}} +\newcommand{\typ}[1]{\lstinline{#1}} \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } @@ -70,12 +70,11 @@ % postbreak = \space\dots % } - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Title page \title[]{Matrices and Arrays\\ \& \\2D Plotting} -\author[Asokan \& Prabhu] {Asokan Pichai\\Prabhu Ramachandran} +\author[FOSSEE Team] {Asokan Pichai\\Prabhu Ramachandran} \institute[FOSSEE] {FOSSEE Team} \date[] {11, October 2009} @@ -171,7 +170,6 @@ array([5, 8, 11, 14]) \item \alert{Note:} \typ{len(arr) != arr.size} in general \item \alert{Note:} By default array operations are performed \alert{elementwise} - \item Indices, slicing: just like lists \end{itemize} \end{frame} @@ -193,8 +191,6 @@ dtype('float64') >>> print x[0], x[-1] 10.0 4.0 \end{lstlisting} - -\inctime{10} \end{frame} \begin{frame}[fragile] @@ -218,31 +214,64 @@ array([10,11,12,-1]) \begin{itemize} \item Basic \alert{elementwise} math (given two arrays \typ{a, b}): \typ{+, -, *, /, \%} - \item Inplace operators: \typ{a += b}, or \typ{add(a, b, - a)} etc. + \item Inplace operators: \typ{a += b}, or \typ{add(a, b, a)} etc. + \item \typ{sum(x, axis=0)}, + \typ{product(x, axis=0)}, + \typ{dot(a, bp)} + \end{itemize} +\end{frame} + +\end{frame} +\begin{frame}[fragile] + \frametitle{Array math cont.} + \begin{itemize} \item Logical operations: \typ{equal (==)}, \typ{not\_equal (!=)}, \typ{less (<)}, \typ{greater (>)} etc. - \item Trig and other functions: \typ{sin(x), arcsin(x), sinh(x), - exp(x), sqrt(x)} etc. - \item \typ{sum(x, axis=0), product(x, axis=0)} - \item \typ{dot(a, bp)} + \item Trig and other functions: \typ{sin(x),} + \typ{arcsin(x), sinh(x),} + \typ{exp(x), sqrt(x)} etc. \end{itemize} - \inctime{10} +\inctime{10} \end{frame} \subsection{Array Creation \& Slicing, Striding Arrays} \begin{frame}[fragile] \frametitle{Array creation functions} + \begin {block}{\typ{array(object, dtype=None, ...)}} + \begin{lstlisting} + >>> array( [2,3,4] ) + array([2, 3, 4]) + \end{lstlisting} + \end {block} + \begin{block}{\typ{linspace(start, stop, num=50, ...)}} + \begin{lstlisting} + >>> linspace( 0, 2, 4 ) + array([0.,0.6666667,1.3333333,2.]) + \end{lstlisting} + \end{block} \begin{itemize} - \item \typ{array(object, dtype=None, \ldots)} - \item \typ{arange(start, stop=None, step=1 \ldots)} - \item \typ{linspace(start, stop, num=50, \ldots)} - \item \typ{ones(shape, dtype=None, \ldots)} - \item \typ{zeros(shape, dtype=float,\ldots)} - \item \typ{identity(n)} - \item \typ{empty(shape, dtype=float,\ldots)} - \item \typ{ones\_like(x)}, - \item \typ{zeros\_like(x)}, \typ{empty\_like(x)} + \item also try \typ{arange} command + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Array creation functions cont.} + \begin{itemize} + \item \typ{ones(shape, dtype=None, ...)} + \begin{lstlisting} + >>>ones([2,2]) + array([[ 1., 1.], + [ 1., 1.]]) + \end{lstlisting} + \item \typ{identity(n)} + \item \typ{ones\_like(x)} + \begin{lstlisting} + >>>a = array([[1,2,3],[4,5,6]]) + >>>ones_like(a) + array([[1, 1, 1], + [1, 1, 1]]) + \end{lstlisting} + \item check out \typ{zeros, zeros\_like, empty} \end{itemize} \end{frame} @@ -258,6 +287,8 @@ array([[5, 6], [8, 9]]) >>> a[:,2] array([3, 6, 9]) +>>> a[...,2] +array([3, 6, 9]) \end{lstlisting} \end{frame} @@ -286,7 +317,17 @@ array([[ 0.96276665, 0.77174861], \end{frame} \begin{frame}[fragile] - \frametitle{Problem set 1.0} + \frametitle{Problem Set} + \begin{lstlisting} + >>> from scipy import misc + >>> A=misc.imread(name) + >>> misc.imshow(A) + \end{lstlisting} + \begin{enumerate} + \item Convert an RGB image to Grayscale. $ Y = 0.5R + 0.25G + 0.25B $ + \item Scale the image to 50\% + \item Introduce some random noise? + \end{enumerate} \inctime{15} \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -296,9 +337,11 @@ array([[ 0.96276665, 0.77174861], \begin{frame} {IPython's \typ{pylab} mode} +\begin{block}{Immediate use:} + \typ{\$ ipython -pylab} +\end{block} \begin{itemize} - \item \typ{pylab}: convenient 2D plotting interface to MPL - \item Immediate use: \typ{ipython -pylab} + \item \typ{pylab}: convenient 2D plotting interface to MPL \item Imports all of pylab for you! \item Allows for interactive plotting \end{itemize} @@ -320,11 +363,12 @@ array([[ 0.96276665, 0.77174861], \begin{itemize} \item Also: PNG, PDF, PS, EPS, SVG, PDF \end{itemize} +\inctime{5} \end{frame} \subsection{Plots - Lines, Labels and Legends} \begin{frame}[fragile] - \frametitle{Basic plotting \ldots} + \frametitle{Tweaking plots} \begin{lstlisting} # Set properties of objects: >>> l, = plot(x, sin(x)) @@ -332,29 +376,37 @@ array([[ 0.96276665, 0.77174861], >>> setp(l, linewidth=2.0, color='r') >>> l.set_linewidth(2.0) >>> draw() # Redraw. ->>> setp(l) # Print properties +>>> setp(l) # Print properties. >>> clf() # Clear figure. >>> close() # Close figure. \end{lstlisting} \end{frame} \begin{frame}[fragile] - \frametitle{Multiple figures} - + \frametitle{Working with text \ldots} +%\begin{itemize} +% \item We already saw LaTeX markup support! +%\end{itemize} \begin{lstlisting} ->>> figure(1) ->>> plot(x, sin(x)) ->>> figure(2) ->>> plot(x, tanh(x)) ->>> figure(1) ->>> title('Easy as 1,2,3') +>>> w = arange(-2,2,.1) +>>> plot(w,exp(-(w*w))*cos) +>>> ylabel('$f(\omega)$') +>>> xlabel('$\omega$') +>>> title(r"$f(\omega)=e^{-\omega^2} + cos({\omega^2})$") +>>> annotate('maxima',xy=(0, 1), + xytext=(1, 0.8), + arrowprops=dict( + facecolor='black', + shrink=0.05)) \end{lstlisting} \end{frame} \begin{frame}[fragile] - \frametitle{Legends and Annotation} + \frametitle{Legends} \begin{lstlisting} +>>> x = linspace(0, 2*pi, 1000) >>> plot(x, cos(5*x), 'r--', label='cosine') >>> plot(x, sin(5*x), 'g--', @@ -362,36 +414,22 @@ array([[ 0.96276665, 0.77174861], >>> legend() # Or use: >>> legend(['cosine', 'sine']) -# Annotation: ->>> text(1,0, '(1,0)') \end{lstlisting} \end{frame} \begin{frame}[fragile] - \frametitle{More commands \ldots} - \begin{lstlisting} -# semilog, loglog ->>> x = 10.**(-arange(100)*0.1) ->>> semilogx(x, x) ->>> semilogy(x, x) ->>> loglog(x, x) ->>> loglog(x, x*x) - \end{lstlisting} -\end{frame} + \frametitle{Multiple figures} + +\begin{lstlisting} +>>> figure(1) +>>> plot(x, sin(x)) +>>> figure(2) +>>> plot(x, tanh(x)) +>>> figure(1) +>>> title('Easy as 1,2,3') +\end{lstlisting} + -\begin{frame}[fragile] - \frametitle{More plots \ldots} - \begin{lstlisting} ->>> clf() ->>> t = arange(0.1, 4, 0.1) ->>> s = exp(-t) ->>> e = 0.1*abs(randn(len(s))) ->>> errorbar(t, s, e) -# Scatter plots ->>> clf() ->>> t = randn(len(e)) ->>> scatter(t, e, c=s) - \end{lstlisting} \end{frame} \begin{frame}[fragile] @@ -404,6 +442,7 @@ pylab.plot(x, pylab.sin(x)) # Can also use: from pylab import linspace, sin, plot \end{lstlisting} +\inctime{5} \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -696,11 +735,12 @@ title('triangular head; scale '\ \end{frame} \begin{frame}[fragile] \frametitle{Maps} - \includegraphics[height=2.5in, interpolate=true]{data/plotmap} + \includegraphics[height=2.3in, interpolate=true]{data/plotmap} \begin{center} \tiny For details see \url{http://matplotlib.sourceforge.net/screenshots/plotmap.py} \end{center} +\inctime{5} \end{frame} @@ -711,22 +751,23 @@ title('triangular head; scale '\ \item \url{http://matplotlib.sf.net/tutorial.html} \item \url{http://matplotlib.sf.net/screenshots.html} \end{itemize} - - \inctime{25} \end{frame} \begin{frame} - \frametitle{Problem set 1.0} + \frametitle{Problem Set} \begin{enumerate} - \item Write a function that plots any n-gon given \typ{n}. + \item Write a function that plots any regular n-gon given \typ{n}. \item Consider the logistic map, $f(x) = kx(1-x)$, plot it for - $k=2.5, 3.5$ and $4$ + $k=2.5, 3.5$ and $4$ in the same plot. \end{enumerate} \end{frame} -\begin{frame} - \frametitle{Problem set 1.1} - \begin{enumerate} +\begin{frame}[fragile] +\frametitle{Problem Set} + \begin{columns} + \column{0.6\textwidth} + \small{ + \begin{enumerate} \item Consider the iteration $x_{n+1} = f(x_n)$ where $f(x) = kx(1-x)$. Plot the successive iterates of this process. \item Plot this using a cobweb plot as follows: @@ -737,28 +778,11 @@ title('triangular head; scale '\ \item Draw line to $(x_i, x_i)$ \item Repeat from 2 for as long as you want \end{enumerate} - \end{enumerate} -\end{frame} - -\begin{frame} - \frametitle{Problem set 1.2} - \begin{enumerate} - - \item Plot the Koch snowflake. Write a function to generate the - necessary points given the two points constituting a line. - \pause - \begin{enumerate} - \item Split the line into 4 segments. - \item The first and last segments are trivial. - \item To rotate the point you can use complex numbers, - recall that $z e^{j \theta}$ rotates a point $z$ in 2D - by $\theta$. - \item Do this for all line segments till everything is - done. - \end{enumerate} - \item Show rate of convergence for a first and second order finite - difference of sin(x) -\end{enumerate} -\inctime{30} + \end{enumerate}} + \column{0.35\textwidth} + \hspace*{-0.5in} + \includegraphics[height=1.6in, interpolate=true]{data/cobweb} +\end{columns} +\inctime{20} \end{frame} \end{document} |