day2/session1.tex
changeset 20 84458ebb6951
parent 12 996fb264fbe2
child 34 5218871f98f4
equal deleted inserted replaced
19:be0f830bdb71 20:84458ebb6951
    49 }
    49 }
    50 \newcounter{time}
    50 \newcounter{time}
    51 \setcounter{time}{0}
    51 \setcounter{time}{0}
    52 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
    52 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
    53 
    53 
    54 \newcommand{\typ}[1]{\texttt{#1}}
    54 \newcommand{\typ}[1]{\lstinline{#1}}
    55 
    55 
    56 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
    56 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
    57 
    57 
    58 %%% This is from Fernando's setup.
    58 %%% This is from Fernando's setup.
    59 % \usepackage{color}
    59 % \usepackage{color}
    72 
    72 
    73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    74 % Title page
    74 % Title page
    75 \title[]{Matrices and Arrays\\ \& \\2D Plotting}
    75 \title[]{Matrices and Arrays\\ \& \\2D Plotting}
    76 
    76 
    77 \author[Asokan \& Prabhu] {Asokan Pichai\\Prabhu Ramachandran}
    77 \author[FOSSEE Team] {Asokan Pichai\\Prabhu Ramachandran}
    78 
    78 
    79 \institute[FOSSEE] {FOSSEE Team}
    79 \institute[FOSSEE] {FOSSEE Team}
    80 \date[] {11, October 2009}
    80 \date[] {11, October 2009}
    81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    82 
    82 
   212 \begin{frame}[fragile]
   212 \begin{frame}[fragile]
   213   \frametitle{Array math}
   213   \frametitle{Array math}
   214   \begin{itemize}
   214   \begin{itemize}
   215   \item Basic \alert{elementwise} math (given two arrays \typ{a, b}):
   215   \item Basic \alert{elementwise} math (given two arrays \typ{a, b}):
   216       \typ{+, -, *, /, \%}
   216       \typ{+, -, *, /, \%}
   217   \item Inplace operators: \typ{a += b}, or \typ{add(a, b,
   217   \item Inplace operators: \typ{a += b}, or \typ{add(a, b, a)} etc. 
   218       a)} etc.
   218   \item \typ{sum(x, axis=0)}, 
       
   219         \typ{product(x, axis=0)},
       
   220         \typ{dot(a, bp)}   
       
   221   \end{itemize}
       
   222 \end{frame}
       
   223 
       
   224 \end{frame}
       
   225 \begin{frame}[fragile]
       
   226   \frametitle{Array math cont.}
       
   227   \begin{itemize}
   219   \item Logical operations: \typ{equal (==)}, \typ{not\_equal (!=)},
   228   \item Logical operations: \typ{equal (==)}, \typ{not\_equal (!=)},
   220     \typ{less (<)}, \typ{greater (>)} etc.
   229     \typ{less (<)}, \typ{greater (>)} etc.
   221   \item Trig and other functions: \typ{sin(x), arcsin(x), sinh(x),
   230   \item Trig and other functions: \typ{sin(x),}
   222       exp(x), sqrt(x)} etc.
   231         \typ{arcsin(x), sinh(x),}
   223   \item \typ{sum(x, axis=0), product(x, axis=0), dot(a, bp)}   \inctime{10}
   232       \typ{exp(x), sqrt(x)} etc.
   224   \end{itemize}
   233   \end{itemize}
       
   234 \inctime{10}
   225 \end{frame}
   235 \end{frame}
   226 
   236 
   227 \subsection{Array Creation \& Slicing, Striding Arrays}
   237 \subsection{Array Creation \& Slicing, Striding Arrays}
   228 \begin{frame}[fragile]
   238 \begin{frame}[fragile]
   229   \frametitle{Array creation functions}
   239   \frametitle{Array creation functions}
       
   240   \begin {block}{\typ{array(object, dtype=None, ...)}}
       
   241   \begin{lstlisting}
       
   242   >>> array( [2,3,4] )  
       
   243   array([2, 3, 4])
       
   244   \end{lstlisting}
       
   245   \end {block}
       
   246   \begin{block}{\typ{linspace(start, stop, num=50, ...)}}
       
   247   \begin{lstlisting}
       
   248   >>> linspace( 0, 2, 4 )   
       
   249   array([0.,0.6666667,1.3333333,2.])
       
   250   \end{lstlisting}
       
   251   \end{block}
   230   \begin{itemize}
   252   \begin{itemize}
   231   \item \typ{array(object, dtype=None, \ldots)}
   253   \item also try \typ{arange} command
   232   \item \typ{arange(start, stop=None, step=1 \ldots)}
   254   \end{itemize}
   233   \item \typ{linspace(start, stop, num=50, \ldots)}
   255 \end{frame}
   234   \item \typ{ones(shape, dtype=None, \ldots)}
   256 
   235   \item \typ{zeros(shape, dtype=float,\ldots)}
   257 \begin{frame}[fragile]
   236   \item \typ{identity(n)}
   258   \frametitle{Array creation functions cont.}
   237   \item \typ{empty(shape, dtype=float,\ldots)}
   259   \begin{itemize}  
   238   \item \typ{ones\_like(x)}, 
   260   \item \typ{ones(shape, dtype=None, ...)}  
   239   \item \typ{zeros\_like(x)}, \typ{empty\_like(x)}
   261   \begin{lstlisting} 
       
   262   >>>ones([2,2])
       
   263   array([[ 1.,  1.],
       
   264        [ 1.,  1.]])
       
   265   \end{lstlisting}  
       
   266   \item \typ{identity(n)} 
       
   267   \item \typ{ones\_like(x)}  
       
   268   \begin{lstlisting} 
       
   269   >>>a = array([[1,2,3],[4,5,6]])
       
   270   >>>ones_like(a)
       
   271     array([[1, 1, 1],
       
   272            [1, 1, 1]])
       
   273   \end{lstlisting}
       
   274   \item check out \typ{zeros, zeros\_like, empty}
   240   \end{itemize}
   275   \end{itemize}
   241 \end{frame}
   276 \end{frame}
   242 
   277 
   243 \begin{frame}[fragile]
   278 \begin{frame}[fragile]
   244   \frametitle{Slicing arrays}
   279   \frametitle{Slicing arrays}
   300 \section{2D Plotting}
   335 \section{2D Plotting}
   301 \subsection{Getting Started}
   336 \subsection{Getting Started}
   302 
   337 
   303 \begin{frame}
   338 \begin{frame}
   304     {IPython's \typ{pylab} mode}
   339     {IPython's \typ{pylab} mode}
       
   340 \begin{block}{Immediate use:}
       
   341  \typ{\$ ipython -pylab}
       
   342 \end{block}
   305 \begin{itemize}
   343 \begin{itemize}
   306     \item \typ{pylab}: convenient 2D plotting interface to MPL
   344     \item \typ{pylab}: convenient 2D plotting interface to MPL    
   307     \item Immediate use: \typ{ipython -pylab}
       
   308     \item Imports all of pylab for you!
   345     \item Imports all of pylab for you!
   309     \item Allows for interactive plotting
   346     \item Allows for interactive plotting
   310 \end{itemize}
   347 \end{itemize}
   311 \end{frame}
   348 \end{frame}
   312 
   349 
   337 >>> l, = plot(x, sin(x))
   374 >>> l, = plot(x, sin(x))
   338 # Why "l,"?
   375 # Why "l,"?
   339 >>> setp(l, linewidth=2.0, color='r')
   376 >>> setp(l, linewidth=2.0, color='r')
   340 >>> l.set_linewidth(2.0)
   377 >>> l.set_linewidth(2.0)
   341 >>> draw() # Redraw.
   378 >>> draw() # Redraw.
   342 >>> setp(l) # Print properties
   379 >>> setp(l) # Print properties.
   343 >>> clf() # Clear figure.
   380 >>> clf() # Clear figure.
   344 >>> close() # Close figure.
   381 >>> close() # Close figure.
   345 \end{lstlisting}
   382 \end{lstlisting}
   346 \end{frame}
   383 \end{frame}
   347 
   384 
   717 \end{frame}
   754 \end{frame}
   718 
   755 
   719 \begin{frame}
   756 \begin{frame}
   720   \frametitle{Problem Set}
   757   \frametitle{Problem Set}
   721   \begin{enumerate}
   758   \begin{enumerate}
   722       \item Write a function that plots any n-gon given \typ{n}.
   759       \item Write a function that plots any regular n-gon given \typ{n}.
   723       \item Consider the logistic map, $f(x) = kx(1-x)$, plot it for
   760       \item Consider the logistic map, $f(x) = kx(1-x)$, plot it for
   724           $k=2.5, 3.5$ and $4$
   761           $k=2.5, 3.5$ and $4$ in the same plot.
   725 \end{enumerate}
   762 \end{enumerate}
   726 \end{frame}
   763 \end{frame}
   727 
   764 
   728 \begin{frame}[fragile] 
   765 \begin{frame}[fragile] 
   729 \frametitle{Problem Set}
   766 \frametitle{Problem Set}