getting_started_with_arrays/slides.tex
changeset 522 d33698326409
equal deleted inserted replaced
521:88a01948450d 522:d33698326409
       
     1 % Created 2010-11-07 Sun 15:18
       
     2 \documentclass[presentation]{beamer}
       
     3 \usepackage[latin1]{inputenc}
       
     4 \usepackage[T1]{fontenc}
       
     5 \usepackage{fixltx2e}
       
     6 \usepackage{graphicx}
       
     7 \usepackage{longtable}
       
     8 \usepackage{float}
       
     9 \usepackage{wrapfig}
       
    10 \usepackage{soul}
       
    11 \usepackage{t1enc}
       
    12 \usepackage{textcomp}
       
    13 \usepackage{marvosym}
       
    14 \usepackage{wasysym}
       
    15 \usepackage{latexsym}
       
    16 \usepackage{amssymb}
       
    17 \usepackage{hyperref}
       
    18 \tolerance=1000
       
    19 \usepackage[english]{babel} \usepackage{ae,aecompl}
       
    20 \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
       
    21 \usepackage{listings}
       
    22 \lstset{language=Python, basicstyle=\ttfamily\bfseries,
       
    23 commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
       
    24 showstringspaces=false, keywordstyle=\color{blue}\bfseries}
       
    25 \providecommand{\alert}[1]{\textbf{#1}}
       
    26 
       
    27 \title{Getting started with arrays}
       
    28 \author{FOSSEE}
       
    29 \date{}
       
    30 
       
    31 \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
       
    32 \begin{document}
       
    33 
       
    34 \maketitle
       
    35 
       
    36 
       
    37 
       
    38 
       
    39 
       
    40 
       
    41 
       
    42 
       
    43 
       
    44 \begin{frame}
       
    45 \frametitle{Outline}
       
    46 \label{sec-1}
       
    47 
       
    48 \begin{itemize}
       
    49 \item Arrays
       
    50 
       
    51 \begin{itemize}
       
    52 \item why arrays over lists
       
    53 \end{itemize}
       
    54 
       
    55 \item Creating arrays
       
    56 \item Array operations
       
    57 \end{itemize}
       
    58 \end{frame}
       
    59 \begin{frame}
       
    60 \frametitle{Overview of Arrays}
       
    61 \label{sec-2}
       
    62 
       
    63 \begin{itemize}
       
    64 \item Arrays are homogeneous data structures.
       
    65 
       
    66 \begin{itemize}
       
    67 \item elements have to the same data type
       
    68 \end{itemize}
       
    69 
       
    70 \item Arrays are faster compared to lists
       
    71 
       
    72 \begin{itemize}
       
    73 \item at least \emph{80-100 times} faster than lists
       
    74 \end{itemize}
       
    75 
       
    76 \end{itemize}
       
    77 \end{frame}
       
    78 \begin{frame}[fragile]
       
    79 \frametitle{Creating Arrays}
       
    80 \label{sec-3}
       
    81 
       
    82 \begin{itemize}
       
    83 \item Creating a 1-dimensional array
       
    84 \end{itemize}
       
    85 
       
    86 \begin{verbatim}
       
    87    In []: a1 = array([1, 2, 3, 4])
       
    88 \end{verbatim}
       
    89 
       
    90   \texttt{[1, 2, 3, 4]} is a list.
       
    91 \end{frame}
       
    92 \begin{frame}[fragile]
       
    93 \frametitle{Creating two-dimensional array}
       
    94 \label{sec-4}
       
    95 
       
    96 \begin{itemize}
       
    97 \item Creating a 2-dimensional array
       
    98 \end{itemize}
       
    99 
       
   100 \begin{verbatim}
       
   101    In []: a2 = array([[1,2,3,4],[5,6,7,8]])
       
   102 \end{verbatim}
       
   103 
       
   104   here we convert a list of lists to an array making a 2-d array.
       
   105 \begin{itemize}
       
   106 \item Easier method of creating array with consecutive elements.
       
   107 \end{itemize}
       
   108 
       
   109 \begin{verbatim}
       
   110    In []: ar = arange(1,9)
       
   111 \end{verbatim}
       
   112 \end{frame}
       
   113 \begin{frame}[fragile]
       
   114 \frametitle{\texttt{reshape()} method}
       
   115 \label{sec-5}
       
   116 
       
   117 \begin{itemize}
       
   118 \item To reshape an array
       
   119 \end{itemize}
       
   120 
       
   121 \begin{verbatim}
       
   122    In []: ar.reshape(2, 4)
       
   123    In []: ar.reshape(4, 2)
       
   124    In []: ar = ar.reshape(2, 4)
       
   125 \end{verbatim}
       
   126 \end{frame}
       
   127 \begin{frame}[fragile]
       
   128 \frametitle{Creating \texttt{array} from \texttt{list}.}
       
   129 \label{sec-6}
       
   130 
       
   131 \begin{itemize}
       
   132 \item \texttt{array()} method accepts list as argument
       
   133 \item Creating a list
       
   134 \begin{verbatim}
       
   135     In []: l1 = [1, 2, 3, 4]
       
   136 \end{verbatim}
       
   137 
       
   138 \item Creating an array
       
   139 \begin{verbatim}
       
   140      In []: a3 = array(l1)
       
   141 \end{verbatim}
       
   142 
       
   143 \end{itemize}
       
   144 \end{frame}
       
   145 \begin{frame}
       
   146 \frametitle{Exercise 1}
       
   147 \label{sec-7}
       
   148 
       
   149   Create a 3-dimensional array of the order (2, 2, 4).
       
   150 \end{frame}
       
   151 \begin{frame}[fragile]
       
   152 \frametitle{\texttt{.shape} of array}
       
   153 \label{sec-8}
       
   154 
       
   155 \begin{itemize}
       
   156 \item \texttt{.shape}
       
   157     To find the shape of the array
       
   158 \begin{verbatim}
       
   159      In []: a1.shape
       
   160 \end{verbatim}
       
   161 
       
   162 \item \texttt{.shape}
       
   163     returns a tuple of shape
       
   164 \end{itemize}
       
   165 \end{frame}
       
   166 \begin{frame}
       
   167 \frametitle{Exercise 2}
       
   168 \label{sec-9}
       
   169 
       
   170   Find out the shape of the other arrays(a2, a3, ar) that we have created.
       
   171 \end{frame}
       
   172 \begin{frame}[fragile]
       
   173 \frametitle{Homogeneous data}
       
   174 \label{sec-10}
       
   175 
       
   176 \begin{itemize}
       
   177 \item All elements in array should be of same type
       
   178 \begin{verbatim}
       
   179      In []: a4 = array([1,2,3,'a string'])
       
   180 \end{verbatim}
       
   181 
       
   182 \end{itemize}
       
   183 \end{frame}
       
   184 \begin{frame}[fragile]
       
   185 \frametitle{Implicit type casting}
       
   186 \label{sec-11}
       
   187 
       
   188 \begin{verbatim}
       
   189     In []: a4
       
   190 \end{verbatim}
       
   191 
       
   192     All elements are type casted to string type
       
   193 \end{frame}
       
   194 \begin{frame}
       
   195 \frametitle{\texttt{identity()}, \texttt{zeros()} methods}
       
   196 \label{sec-12}
       
   197 
       
   198 \begin{itemize}
       
   199 \item \texttt{identity(n)}
       
   200     Creates an identity matrix, a square matrix of order (n, n) with diagonal elements 1 and others 0.
       
   201 \item \texttt{zeros((m, n))}
       
   202     Creates an \texttt{m X n} matrix with all elements 0.
       
   203 \end{itemize}
       
   204 \end{frame}
       
   205 \begin{frame}
       
   206 \frametitle{Learning exercise}
       
   207 \label{sec-13}
       
   208 
       
   209 \begin{itemize}
       
   210 \item Find out about
       
   211 
       
   212 \begin{itemize}
       
   213 \item \texttt{zeros\_like()}
       
   214 \item \texttt{ones()}
       
   215 \item \texttt{ones\_like()}
       
   216 \end{itemize}
       
   217 
       
   218 \end{itemize}
       
   219 \end{frame}
       
   220 \begin{frame}
       
   221 \frametitle{Array operations}
       
   222 \label{sec-14}
       
   223 
       
   224 \begin{itemize}
       
   225 \item \texttt{a1 * 2}
       
   226     returns a new array with all elements of \texttt{a1} multiplied by \texttt{2}.
       
   227 
       
   228 \begin{itemize}
       
   229 \item Similarly \texttt{+}, \texttt{-} \& \texttt{/}.
       
   230 \end{itemize}
       
   231 
       
   232 \item \texttt{a1 + 2}
       
   233     returns a new array with all elements of \texttt{a1} summed with \texttt{2}.
       
   234 \item \texttt{a1 += 2}
       
   235     adds \texttt{2} to all elements of array \texttt{a1}.
       
   236 
       
   237 \begin{itemize}
       
   238 \item Similarly \texttt{-=}, \texttt{*=} \& \texttt{/=}.
       
   239 \end{itemize}
       
   240 
       
   241 \item \texttt{a1 + a2}
       
   242     does elements-wise addition.
       
   243 
       
   244 \begin{itemize}
       
   245 \item Similarly \texttt{-}, \texttt{*} \& \texttt{/}.
       
   246 \end{itemize}
       
   247 
       
   248 \item \texttt{a1 * a2}
       
   249     does element-wise multiplication
       
   250 \end{itemize}
       
   251 
       
   252 
       
   253   \textbf{Note} - array(A) * array(B) does element wise multiplication and not matrix multiplication
       
   254 \end{frame}
       
   255 \begin{frame}
       
   256 \frametitle{Summary}
       
   257 \label{sec-15}
       
   258 
       
   259   In this tutorial we covered,
       
   260 \begin{itemize}
       
   261 \item Basics of arrays
       
   262 \item Creating arrays
       
   263 \item Arrays from lists
       
   264 \item Basic array operations
       
   265 \end{itemize}
       
   266 \end{frame}
       
   267 \begin{frame}
       
   268 \frametitle{Thank you!}
       
   269 \label{sec-16}
       
   270 
       
   271   \begin{block}{}
       
   272   \begin{center}
       
   273   This spoken tutorial has been produced by the
       
   274   \textcolor{blue}{FOSSEE} team, which is funded by the 
       
   275   \end{center}
       
   276   \begin{center}
       
   277     \textcolor{blue}{National Mission on Education through \\
       
   278       Information \& Communication Technology \\ 
       
   279       MHRD, Govt. of India}.
       
   280   \end{center}  
       
   281   \end{block}
       
   282 \end{frame}
       
   283 
       
   284 \end{document}