day1quiz2.tex
changeset 334 2214b5dba4d4
parent 306 57291186d598
child 343 adb85e126341
equal deleted inserted replaced
333:25b18b51be41 334:2214b5dba4d4
    33 \setcounter{qno}{0}
    33 \setcounter{qno}{0}
    34 \newcommand{\incqno}{\addtocounter{qno}{1}{Question \theqno}}
    34 \newcommand{\incqno}{\addtocounter{qno}{1}{Question \theqno}}
    35 
    35 
    36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    37 % Title page
    37 % Title page
    38 \title[Basic Python]{Python: Quiz}
    38 \title[Basic Python]{Python for science and engineering: Day 1, Quiz 2}
    39 
    39 
    40 \author[FOSSEE Team] {FOSSEE}
    40 \author[FOSSEE Team] {FOSSEE}
    41 
    41 
    42 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    42 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    43 \date[] {11, October 2009\\Day 2}
    43 \date[] {\today \\
       
    44 Day 1, quiz 2}
    44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    45 
    46 
    46 
    47 
    47 \begin{document}
    48 \begin{document}
    48 
    49 
    52 
    53 
    53 \begin{frame}
    54 \begin{frame}
    54   \frametitle{Write your details...}
    55   \frametitle{Write your details...}
    55 On the top right hand corner please write down the following:
    56 On the top right hand corner please write down the following:
    56   \begin{itemize}
    57   \begin{itemize}
    57     \item  Name:
    58     \item Name:
    58     \item Affliation:
    59     \item University/College/Company:
    59     \item Occupation:
    60     \item Student/Teacher/Professional:
    60   \end{itemize}
    61   \end{itemize}
    61 \end{frame}
    62 \end{frame}
    62 
    63 
    63 \begin{frame}[fragile]
    64 %% \begin{frame}[fragile]
    64 \frametitle{\incqno }
    65 %% \frametitle{\incqno }
    65 \begin{lstlisting}
    66 %% \begin{lstlisting}
    66   >>> x = array([[1,2,3,4],[3,4,2,5]])
    67 %%   In []: x = array([[1,2,3,4],
    67   >>> x.shape
    68 %%                     [3,4,2,5]])
    68   (2, 4)
    69 %% \end{lstlisting}
    69 \end{lstlisting}
    70 %% What is the \lstinline+shape+ of this array?
    70 Change the shape of \lstinline+x+ to (4,2)
    71 %% \end{frame}
    71 \end{frame}
    72 
    72 
    73 
    73 \begin{frame}[fragile]
    74 \begin{frame}[fragile]
    74 \frametitle{\incqno }
    75 \frametitle{\incqno }
    75 \begin{lstlisting}
    76 \begin{lstlisting}
    76   >>> x = array([[1,2,3,4]])
    77   In []: x = array([[1,2,3,4]])
    77 \end{lstlisting}
    78 \end{lstlisting}
    78 How to change the third element of \lstinline+x+ to 0?
    79 How to change the third element (i.e.\ 3) of \lstinline+x+ to 0?
    79 \end{frame}
    80 \end{frame}
    80 
    81 
    81 \begin{frame}[fragile]
    82 \begin{frame}[fragile]
    82 \frametitle{\incqno }
    83 \frametitle{\incqno }
    83 What would be the result?
    84 \begin{lstlisting}
    84 \begin{lstlisting}
    85   In []: x = array([[1,2,3,4],
    85   >>> y = arange(3)
    86                     [3,4,2,5]])
    86   >>> x = linspace(0,3,3)
    87 \end{lstlisting}
    87   >>> x-y
    88 How do you get the following slice of \lstinline+x+?
    88 \end{lstlisting}
    89 \begin{lstlisting}
    89 \end{frame}
    90 array([[2,3],
    90 
    91        [4,2]])
    91 \begin{frame}[fragile]
    92 \end{lstlisting}
    92 \frametitle{\incqno }
    93 \end{frame}
    93 \begin{lstlisting}
    94 
    94   >>> x = array([0, 1, 2, 3])
    95 
    95   >>> x.shape = 2,2
    96 %% \begin{frame}
    96   >>> x
    97 %% \frametitle{\incqno }
    97   array([[0, 1],
    98 %% The file \lstinline+datafile.txt+ contains 3 columns of data.  What
    98          [2, 3]])
    99 %% command will you use to read the entire data file into an array?
    99   >>> x[::2,::2]
   100 %% \end{frame}
   100 \end{lstlisting}
   101 
   101 What is the output?
   102 %% \begin{frame}
   102 \end{frame}
   103 %% \frametitle{\incqno }
   103 
   104 
   104 \begin{frame}[fragile]
   105 %% If the contents of the file \lstinline+datafile.txt+ is read into an
   105 \frametitle{\incqno }
   106 %% $N\times3$ array called \lstinline+data+, how would you obtain the third
   106 What would be the result?
   107 %% column of this data?
   107 \begin{lstlisting}
   108 
   108   >>> x
   109 %% \end{frame}
   109   array([[0, 1, 2],
   110 
   110          [3, 4, 5],
   111 \begin{frame}[fragile]
   111          [6, 7, 8]])
   112 \frametitle{\incqno }
   112   >>> x[::-1,:]
   113 \begin{lstlisting}
   113 \end{lstlisting}
   114   In []: x = array(([1,2,3,4],
   114 Hint:
   115                     [2,3,4,5]))
   115 \begin{lstlisting}
   116   In []: x[-2][-3] = 4
   116   >>> x = arange(9)
   117   In []: print x
   117   >>> x[::-1]
       
   118   array([8, 7, 6, 5, 4, 3, 2, 1, 0])
       
   119 \end{lstlisting}
       
   120 \end{frame}
       
   121 
       
   122 \begin{frame}[fragile]
       
   123 \frametitle{\incqno }
       
   124 \begin{lstlisting}
       
   125   >>> x
       
   126   array([[ 0, 1, 2, 3],
       
   127          [ 4, 5, 6, 7],
       
   128          [ 8, 9, 10, 11],
       
   129          [12, 13, 14, 15]])
       
   130 \end{lstlisting}
       
   131 How will you get the following \lstinline+x+?
       
   132 \begin{lstlisting}
       
   133   array([[ 5, 7],
       
   134          [ 9, 11]])
       
   135 \end{lstlisting}
       
   136 \end{frame}
       
   137 
       
   138 \begin{frame}[fragile]
       
   139 \frametitle{\incqno }
       
   140 \begin{lstlisting}
       
   141   >>> x = array(([1,2,3,4],[2,3,4,5]))
       
   142   >>> x[-2][-3] = 4
       
   143   >>> x
       
   144 \end{lstlisting}
   118 \end{lstlisting}
   145 What will be printed?
   119 What will be printed?
   146 \end{frame}
   120 \end{frame}
   147 
   121 
   148 \begin{frame}[fragile]
   122 
   149 \frametitle{\incqno }
   123 %% \begin{frame}[fragile]
   150 What would be the output?
   124 %% \frametitle{\incqno }
   151 \begin{lstlisting}
   125 %% \begin{lstlisting}
   152   >>> y = arange(4)
   126 %%   In []: x = arange(0, 1, 0.25)
   153   >>> x = array(([1,2,3,2],[1,3,6,0]))
   127 %%   In []: print x
   154   >>> x + y
   128 %% \end{lstlisting}
   155 \end{lstlisting}
   129 %% What will be printed?
   156 \end{frame}
   130 %% \end{frame}
   157 
   131 
   158 \begin{frame}[fragile]
   132 
   159 \frametitle{\incqno }
   133 %% \begin{frame}[fragile]
   160 \begin{lstlisting}
   134 %% \frametitle{\incqno }
   161   >>> line = plot(x, sin(x))
   135 %% \begin{lstlisting}
   162 \end{lstlisting}
   136 %% from scipy.integrate import quad
   163 Use the \lstinline+set_linewidth+ method to set width of \lstinline+line+ to 2.
   137 %% def f(x):
   164 \end{frame}
   138 %%     res = x*cos(x)
   165 
   139 
   166 \begin{frame}[fragile]
   140 %% quad(f, 0, 1)
   167 \frametitle{\incqno }
   141 %% \end{lstlisting}
   168 What would be the output?
   142 
   169 \begin{lstlisting}
   143 %% What changes will you make to the above code to make it work?
   170   >>> x = arange(9)
   144 %% \end{frame}
   171   >>> y = arange(9.)
   145 
   172   >>> x == y
   146 %% \begin{frame}
   173 \end{lstlisting}
   147 %% \frametitle{\incqno }
   174 \end{frame}
   148 %% What two commands will you use to create and evaluate a spline given
   175 
   149 %% some data?
       
   150 %% \end{frame}
       
   151 
       
   152 \begin{frame}
       
   153 \frametitle{\incqno }
       
   154 What command will you use if you wish to integrate a system of ODEs?
       
   155 \end{frame}
       
   156 
       
   157 \begin{frame}
       
   158 \frametitle{\incqno }
       
   159 How do you calculate the roots of the polynomial, $y = 1 + 6x + 8x^2 +
       
   160 x^3$?
       
   161 \end{frame}
       
   162 
       
   163 \begin{frame}
       
   164 \frametitle{\incqno }
       
   165 
       
   166 Two arrays \lstinline+a+ and \lstinline+b+ are numerically almost equal, what command
       
   167 do you use to check if this is true?
       
   168 
       
   169 \end{frame}
       
   170 
       
   171 \begin{frame}[fragile]
       
   172 \frametitle{\incqno }
       
   173 \begin{lstlisting}
       
   174 In []: marks = [10, 20, 30, 50, 55, 
       
   175                75, 83] 
       
   176 \end{lstlisting}
       
   177 How will you convert the list \texttt{marks} to an \alert{array}?
       
   178 \end{frame}
       
   179 
       
   180 \begin{frame}[fragile]
       
   181 \frametitle{\incqno }
       
   182 \begin{lstlisting}
       
   183 In []: a = array([[1, 2],
       
   184                   [3, 4]])
       
   185 In []: a[1,0] = 0
       
   186 \end{lstlisting}
       
   187 What is the resulting matrix?
       
   188 \end{frame}
       
   189 
       
   190 \begin{frame}[fragile]
       
   191 \frametitle{\incqno }
       
   192 \begin{lstlisting}
       
   193 In []: a = array([[1, 2],
       
   194                   [3, 4]])
       
   195 \end{lstlisting}
       
   196 How do you get the transpose of this array?
       
   197 \end{frame}
       
   198 
       
   199 \begin{frame}[fragile]
       
   200 \frametitle{\incqno }
       
   201 \begin{lstlisting}
       
   202 In []: a = array([[1, 2],
       
   203                   [3, 4]])
       
   204 In []: b = array([[1, 1],
       
   205                   [2, 2]])
       
   206 In []: a*b
       
   207 \end{lstlisting}
       
   208 What does this produce?
       
   209 \end{frame}
       
   210 
       
   211 \begin{frame}
       
   212 \frametitle{\incqno }
       
   213 What command do you use to find the inverse of a matrix and its
       
   214 eigenvalues?
       
   215 \end{frame}
       
   216 
       
   217 \begin{frame}
       
   218 \frametitle{\incqno }
       
   219 Given a 4x4 matrix \texttt{A} and a 4-vector \texttt{b}, what command do
       
   220 you use to solve for the equation \\
       
   221 \texttt{Ax = b}?
       
   222 \end{frame}
   176 
   223 
   177 \end{document}
   224 \end{document}
   178 
   225 
       
   226 %% \begin{frame}[fragile]
       
   227 %% \frametitle{\incqno }
       
   228 %% What would be the result?
       
   229 %% \begin{lstlisting}
       
   230 %%   In []: x
       
   231 %%   array([[0, 1, 2],
       
   232 %%          [3, 4, 5],
       
   233 %%          [6, 7, 8]])
       
   234 %%   In []: x[::-1,:]
       
   235 %% \end{lstlisting}
       
   236 %% Hint:
       
   237 %% \begin{lstlisting}
       
   238 %%   In []: x = arange(9)
       
   239 %%   In []: x[::-1]
       
   240 %%   array([8, 7, 6, 5, 4, 3, 2, 1, 0])
       
   241 %% \end{lstlisting}
       
   242 %% \end{frame}
       
   243 
       
   244 %% \begin{frame}[fragile]
       
   245 %% \frametitle{\incqno }
       
   246 %% What would be the result?
       
   247 %% \begin{lstlisting}
       
   248 %%   In []: y = arange(3)
       
   249 %%   In []: x = linspace(0,3,3)
       
   250 %%   In []: x-y
       
   251 %% \end{lstlisting}
       
   252 %% \end{frame}
       
   253 
       
   254 %% \begin{frame}[fragile]
       
   255 %% \frametitle{\incqno }
       
   256 %% \begin{lstlisting}
       
   257 %%   In []: x
       
   258 %%   array([[ 0, 1, 2, 3],
       
   259 %%          [ 4, 5, 6, 7],
       
   260 %%          [ 8, 9, 10, 11],
       
   261 %%          [12, 13, 14, 15]])
       
   262 %% \end{lstlisting}
       
   263 %% How will you get the following \lstinline+x+?
       
   264 %% \begin{lstlisting}
       
   265 %%   array([[ 5, 7],
       
   266 %%          [ 9, 11]])
       
   267 %% \end{lstlisting}
       
   268 %% \end{frame}
       
   269 
       
   270 %% \begin{frame}[fragile]
       
   271 %% \frametitle{\incqno }
       
   272 %% What would be the output?
       
   273 %% \begin{lstlisting}
       
   274 %%   In []: y = arange(4)
       
   275 %%   In []: x = array(([1,2,3,2],[1,3,6,0]))
       
   276 %%   In []: x + y
       
   277 %% \end{lstlisting}
       
   278 %% \end{frame}
       
   279 
       
   280 %% \begin{frame}[fragile]
       
   281 %% \frametitle{\incqno }
       
   282 %% \begin{lstlisting}
       
   283 %%   In []: line = plot(x, sin(x))
       
   284 %% \end{lstlisting}
       
   285 %% Use the \lstinline+set_linewidth+ method to set width of \lstinline+line+ to 2.
       
   286 %% \end{frame}
       
   287 
       
   288 %% \begin{frame}[fragile]
       
   289 %% \frametitle{\incqno }
       
   290 %% What would be the output?
       
   291 %% \begin{lstlisting}
       
   292 %%   In []: x = arange(9)
       
   293 %%   In []: y = arange(9.)
       
   294 %%   In []: x == y
       
   295 %% \end{lstlisting}
       
   296 %% \end{frame}
       
   297