getting-started-with-arrays/slides.tex
changeset 304 d98f554bbec0
child 393 f99254fc7d70
equal deleted inserted replaced
300:a130a1f494c3 304:d98f554bbec0
       
     1 % Created 2010-10-12 Tue 00:20
       
     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 \begin{itemize}
       
    91 \item Creating a 2-dimensional array
       
    92 \end{itemize}
       
    93 
       
    94 \begin{verbatim}
       
    95    In []: a2 = array([[1,2,3,4],[5,6,7,8]])
       
    96 \end{verbatim}
       
    97 
       
    98 \begin{itemize}
       
    99 \item Easier method of creating array with consecutive elements.
       
   100 \end{itemize}
       
   101 
       
   102 \begin{verbatim}
       
   103    In []: ar = arange(1,9)
       
   104 \end{verbatim}
       
   105 \end{frame}
       
   106 \begin{frame}[fragile]
       
   107 \frametitle{\texttt{reshape()} method}
       
   108 \label{sec-4}
       
   109 
       
   110 \begin{itemize}
       
   111 \item To reshape an array
       
   112 \end{itemize}
       
   113 
       
   114 \begin{verbatim}
       
   115    In []: ar.reshape(2, 4)
       
   116    In []: ar.reshape(4, 2)
       
   117    In []: ar = ar.reshape(2, 4)
       
   118 \end{verbatim}
       
   119 \end{frame}
       
   120 \begin{frame}[fragile]
       
   121 \frametitle{Creating \texttt{array} from \texttt{list}.}
       
   122 \label{sec-5}
       
   123 
       
   124 \begin{itemize}
       
   125 \item \texttt{array()} method accepts list as argument
       
   126 \item Creating a list
       
   127 \begin{verbatim}
       
   128     In []: l1 = [1, 2, 3, 4]
       
   129 \end{verbatim}
       
   130 
       
   131 \item Creating an array
       
   132 \begin{verbatim}
       
   133      In []: a3 = array(l1)
       
   134 \end{verbatim}
       
   135 
       
   136 \end{itemize}
       
   137 \end{frame}
       
   138 \begin{frame}
       
   139 \frametitle{Exercise 1}
       
   140 \label{sec-6}
       
   141 
       
   142   Create a 3-dimensional array of the order (2, 2, 4).
       
   143 \end{frame}
       
   144 \begin{frame}[fragile]
       
   145 \frametitle{\texttt{.shape} of array}
       
   146 \label{sec-7}
       
   147 
       
   148 \begin{itemize}
       
   149 \item \texttt{.shape}
       
   150     To find the shape of the array
       
   151 \begin{verbatim}
       
   152      In []: a1.shape
       
   153 \end{verbatim}
       
   154 
       
   155 \item \texttt{.shape}
       
   156     returns a tuple of shape
       
   157 \end{itemize}
       
   158 \end{frame}
       
   159 \begin{frame}
       
   160 \frametitle{Exercise 2}
       
   161 \label{sec-8}
       
   162 
       
   163   Find out the shape of the other arrays(a2, a3, ar) that we have created.
       
   164 \end{frame}
       
   165 \begin{frame}[fragile]
       
   166 \frametitle{Homogeneous data}
       
   167 \label{sec-9}
       
   168 
       
   169 \begin{itemize}
       
   170 \item All elements in array should be of same type
       
   171 \begin{verbatim}
       
   172      In []: a4 = array([1,2,3,'a string'])
       
   173 \end{verbatim}
       
   174 
       
   175 \end{itemize}
       
   176 \end{frame}
       
   177 \begin{frame}[fragile]
       
   178 \frametitle{Implicit type casting}
       
   179 \label{sec-10}
       
   180 
       
   181 \begin{verbatim}
       
   182     In []: a4
       
   183 \end{verbatim}
       
   184 
       
   185     All elements are type casted to string type
       
   186 \end{frame}
       
   187 \begin{frame}
       
   188 \frametitle{\texttt{identity()}, \texttt{zeros()} methods}
       
   189 \label{sec-11}
       
   190 
       
   191 \begin{itemize}
       
   192 \item \texttt{identity(n)}
       
   193     Creates an identity matrix, a square matrix of order (n, n) with diagonal elements 1 and others 0.
       
   194 \item \texttt{zeros((m, n))}
       
   195     Creates an \texttt{m X n} matrix with all elements 0.
       
   196 \end{itemize}
       
   197 \end{frame}
       
   198 \begin{frame}
       
   199 \frametitle{Learning exercise}
       
   200 \label{sec-12}
       
   201 
       
   202 \begin{itemize}
       
   203 \item Find out about
       
   204 
       
   205 \begin{itemize}
       
   206 \item \texttt{zeros\_like()}
       
   207 \item \texttt{ones()}
       
   208 \item \texttt{ones\_like()}
       
   209 \end{itemize}
       
   210 
       
   211 \end{itemize}
       
   212 \end{frame}
       
   213 \begin{frame}
       
   214 \frametitle{Array operations}
       
   215 \label{sec-13}
       
   216 
       
   217 \begin{itemize}
       
   218 \item \texttt{a1 * 2}
       
   219     returns a new array with all elements of \texttt{a1} multiplied by \texttt{2}.
       
   220 
       
   221 \begin{itemize}
       
   222 \item Similarly \texttt{+}, \texttt{-} \& \texttt{/}.
       
   223 \end{itemize}
       
   224 
       
   225 \item \texttt{a1 + 2}
       
   226     returns a new array with all elements of \texttt{a1} summed with \texttt{2}.
       
   227 \item \texttt{a1 += 2}
       
   228     adds \texttt{2} to all elements of array \texttt{a1}.
       
   229 
       
   230 \begin{itemize}
       
   231 \item Similarly \texttt{-=}, \texttt{*=} \& \texttt{/=}.
       
   232 \end{itemize}
       
   233 
       
   234 \item \texttt{a1 + a2}
       
   235     does elements-wise addition.
       
   236 
       
   237 \begin{itemize}
       
   238 \item Similarly \texttt{-}, \texttt{*} \& \texttt{/}.
       
   239 \end{itemize}
       
   240 
       
   241 \item \texttt{a1 * a2}
       
   242     does element-wise multiplication
       
   243 \end{itemize}
       
   244 
       
   245 
       
   246   \textbf{Note} - array(A) * array(B) does element wise multiplication and not matrix multiplication
       
   247 \end{frame}
       
   248 \begin{frame}
       
   249 \frametitle{Summary}
       
   250 \label{sec-14}
       
   251 
       
   252   In this tutorial we covered,
       
   253 \begin{itemize}
       
   254 \item Basics of arrays
       
   255 \item Creating arrays
       
   256 \item Arrays from lists
       
   257 \item Basic array operations
       
   258 \end{itemize}
       
   259 \end{frame}
       
   260 \begin{frame}
       
   261 \frametitle{Thank you!}
       
   262 \label{sec-15}
       
   263 
       
   264   \begin{block}{}
       
   265   \begin{center}
       
   266   This spoken tutorial has been produced by the
       
   267   \textcolor{blue}{FOSSEE} team, which is funded by the 
       
   268   \end{center}
       
   269   \begin{center}
       
   270     \textcolor{blue}{National Mission on Education through \\
       
   271       Information \& Communication Technology \\ 
       
   272       MHRD, Govt. of India}.
       
   273   \end{center}  
       
   274   \end{block}
       
   275 \end{frame}
       
   276 
       
   277 \end{document}