day1/session4.tex
changeset 361 a1ee950f3d6d
parent 354 5dc6c3673f9d
child 366 ec4cb3ba7f09
equal deleted inserted replaced
360:cb201fe2ecb1 361:a1ee950f3d6d
   132 \end{frame}
   132 \end{frame}
   133 
   133 
   134 \begin{frame}[fragile]
   134 \begin{frame}[fragile]
   135 \frametitle{Matrices: Initializing}
   135 \frametitle{Matrices: Initializing}
   136 \begin{lstlisting}
   136 \begin{lstlisting}
   137 In []: c = array([[1,1,2],
   137 In [23]: c = array([[11,12,13],
   138                   [2,4,1],
   138                   [21,22,23],
   139                   [-1,3,7]])
   139                   [31,32,33]])
   140 
   140 
   141 In []: c
   141 In []: c
   142 Out[]: 
   142 Out[]: 
   143 array([[1,1,2],
   143 array([[11, 12, 13],
   144        [2,4,1],
   144        [21, 22, 23],
   145        [-1,3,7]])
   145        [31, 32, 33]])
   146 \end{lstlisting}
   146 \end{lstlisting}
   147 \end{frame}
   147 \end{frame}
   148 
   148 
   149 \begin{frame}[fragile]
   149 \begin{frame}[fragile]
   150 \frametitle{Initializing some special matrices}
   150 \frametitle{Initializing some special matrices}
   172 \begin{frame}[fragile]
   172 \begin{frame}[fragile]
   173   \frametitle{Accessing elements}
   173   \frametitle{Accessing elements}
   174   \begin{lstlisting}
   174   \begin{lstlisting}
   175 In []: c
   175 In []: c
   176 Out[]: 
   176 Out[]: 
   177 array([[1,1,2],
   177 array([[11, 12, 13],
   178        [2,4,1],
   178        [21, 22, 23],
   179        [-1,3,7]])
   179        [31, 32, 33]])
   180 
   180 
   181 In []: c[1][2]
   181 In []: c[1][2]
   182 Out[]: 1
   182 Out[]: 23
   183 In []: c[1,2]
   183 In []: c[1,2]
   184 Out[]: 1
   184 Out[]: 23
   185 In []: c[1]
   185 In []: c[1]
   186 Out[]: array([2, 4, 1])
   186 Out[]: array([21, 22, 23])
   187   \end{lstlisting}
   187   \end{lstlisting}
   188 \end{frame}
   188 \end{frame}
   189 
   189 
   190 \begin{frame}[fragile]
   190 \begin{frame}[fragile]
   191   \frametitle{Changing elements}
   191   \frametitle{Changing elements}
   192   \begin{small}
   192   \begin{small}
   193   \begin{lstlisting}
   193   \begin{lstlisting}
   194 In []: c[1,1] = -2
   194 In []: c[1,1] = -22
   195 In []: c
   195 In []: c
   196 Out[]: 
   196 Out[]: 
   197 array([[ 1,  1,  2],
   197 array([[ 11,  12,  13],
   198        [ 2, -2,  1],
   198        [ 21, -22,  23],
   199        [-1,  3,  7]])
   199        [ 31,  32,  33]])
   200 
   200 
   201 In []: c[1] = [0,0,0]
   201 In []: c[1] = 0
   202 In []: c
   202 In []: c
   203 Out[]: 
   203 Out[]: 
   204 array([[ 1,  1,  2],
   204 array([[11, 12, 13],
   205        [ 0,  0,  0],
   205        [ 0,  0,  0],
   206        [-1,  3,  7]])
   206        [31, 32, 33]])
   207   \end{lstlisting}
   207   \end{lstlisting}
   208   \end{small}
   208   \end{small}
   209 How to change one \alert{column}?
   209 How to change one \alert{column}?
   210 \end{frame}
   210 \end{frame}
   211 
   211 
   212 \begin{frame}[fragile]
   212 \begin{frame}[fragile]
   213   \frametitle{Slicing}
   213   \frametitle{Slicing}
   214 \begin{small}
   214 \begin{small}
   215   \begin{lstlisting}
   215   \begin{lstlisting}
   216 In []: c[:,1]
   216 In []: c[:,1]
   217 Out[]: array([1, 0, 3])
   217 Out[]: array([12,  0, 32])
   218 
   218 
   219 In []: c[1,:]
   219 In []: c[1,:]
   220 Out[]: array([0, 0, 0])
   220 Out[]: array([0, 0, 0])
   221 
   221 
   222 In []: c[0:2,:]
   222 In []: c[0:2,:]
   223 Out[]: 
   223 Out[]: 
   224 array([[1, 1, 2],
   224 array([[11, 12, 13],
   225        [0, 0, 0]])
   225        [ 0,  0,  0]])
   226 
   226 
   227 In []: c[1:3,:]
   227 In []: c[1:3,:]
   228 Out[]: 
   228 Out[]: 
   229 array([[ 0,  0,  0],
   229 array([[ 0,  0,  0],
   230        [-1,  3,  7]])
   230        [31, 32, 33]])
   231   \end{lstlisting}
   231   \end{lstlisting}
   232 \end{small}
   232 \end{small}
   233 \end{frame}
   233 \end{frame}
   234 
   234 
   235 \begin{frame}[fragile]
   235 \begin{frame}[fragile]
   236   \frametitle{Slicing \ldots}
   236   \frametitle{Slicing \ldots}
   237 \begin{small}
   237 \begin{small}
   238   \begin{lstlisting}
   238   \begin{lstlisting}
   239 In []: c[:2,:]
   239 In []: c[:2,:]
   240 Out[]: 
   240 Out[]: 
   241 array([[1, 1, 2],
   241 array([[11, 12, 13],
   242        [0, 0, 0]])
   242        [ 0,  0,  0]])
   243 
   243 
   244 In []: c[1:,:]
   244 In []: c[1:,:]
   245 Out[]: 
   245 Out[]: 
   246 array([[ 0,  0,  0],
   246 array([[ 0,  0,  0],
   247        [-1,  3,  7]])
   247        [31, 32, 33]])
   248 
   248 
   249 In []: c[1:,:2]
   249 In []: c[1:,:2]
   250 Out[]: 
   250 Out[]: 
   251 array([[ 0,  0],
   251 array([[ 0,  0],
   252        [-1,  3]])
   252        [31, 32]])
   253   \end{lstlisting}
   253   \end{lstlisting}
   254 
   254 
   255 \end{small}
   255 \end{small}
   256 \end{frame}
   256 \end{frame}
   257 
   257 
   259   \frametitle{Striding}
   259   \frametitle{Striding}
   260   \begin{small}
   260   \begin{small}
   261   \begin{lstlisting}
   261   \begin{lstlisting}
   262 In []: c[::2,:]
   262 In []: c[::2,:]
   263 Out[]: 
   263 Out[]: 
   264 array([[ 1,  1,  2],
   264 array([[11, 12, 13],
   265        [-1,  3,  7]])
   265        [31, 32, 33]])
   266 
   266 
   267 In []: c[:,::2]
   267 In []: c[:,::2]
   268 Out[]: 
   268 Out[]: 
   269 xarray([[ 1,  2],
   269 array([[11, 13],
   270        [ 0,  0],
   270        [ 0,  0],
   271        [-1,  7]])
   271        [31, 33]])
   272 
   272 
   273 In []: c[::2,::2]
   273 In []: c[::2,::2]
   274 Out[]: 
   274 Out[]: 
   275 array([[ 1,  2],
   275 array([[11, 13],
   276        [-1,  7]])
   276        [31, 33]])
   277   \end{lstlisting}
   277   \end{lstlisting}
   278   \end{small}
   278   \end{small}
   279 \end{frame}
   279 \end{frame}
   280 
   280 
   281 \begin{frame}[fragile]
   281 \begin{frame}[fragile]
   475 \end{figure}
   475 \end{figure}
   476 \end{frame}
   476 \end{frame}
   477 
   477 
   478 \begin{frame}
   478 \begin{frame}
   479 \frametitle{Least Square Fit Curve}
   479 \frametitle{Least Square Fit Curve}
       
   480 \begin{center}
   480 \begin{itemize}
   481 \begin{itemize}
   481 \item $T^2$ and $L$ have a linear relationship
   482 \item $L \alpha T^2$
   482 \item Hence, Least Square Fit Curve is a line
   483 \item Best Fit Curve $\rightarrow$ Linear
   483 \item we shall use the \typ{lstsq} function
   484   \begin{itemize}
       
   485   \item Least Square Fit
       
   486   \end{itemize}
       
   487 \item \typ{lstsq()} 
   484 \end{itemize}
   488 \end{itemize}
       
   489 \end{center}
   485 \end{frame}
   490 \end{frame}
   486 
   491 
   487 \begin{frame}[fragile]
   492 \begin{frame}[fragile]
   488 \frametitle{\typ{lstsq}}
   493 \frametitle{\typ{lstsq}}
   489 \begin{itemize}
   494 \begin{itemize}