# HG changeset patch # User Shantanu # Date 1254592203 -19800 # Node ID 84458ebb6951dade7b92f00e0a9cd28fb961fb42 # Parent be0f830bdb71bb4d5b83eb273b3a1108d199d5d3 Modified numpy array parts. diff -r be0f830bdb71 -r 84458ebb6951 day2/session1.tex --- a/day2/session1.tex Sat Oct 03 21:33:55 2009 +0530 +++ b/day2/session1.tex Sat Oct 03 23:20:03 2009 +0530 @@ -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}}} } @@ -74,7 +74,7 @@ % 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} @@ -214,29 +214,64 @@ \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), dot(a, bp)} \inctime{10} + \item Trig and other functions: \typ{sin(x),} + \typ{arcsin(x), sinh(x),} + \typ{exp(x), sqrt(x)} etc. \end{itemize} +\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} @@ -302,9 +337,11 @@ \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} @@ -339,7 +376,7 @@ >>> 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} @@ -719,9 +756,9 @@ \begin{frame} \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}