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