-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathquiz02-practice.tex
148 lines (131 loc) · 3.26 KB
/
quiz02-practice.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
\documentclass[12pt]{article}
\setlength{\topmargin}{-.75in} \addtolength{\textheight}{2.00in}
\setlength{\oddsidemargin}{.00in} \addtolength{\textwidth}{.75in}
\usepackage{amsmath,color,graphicx}
\usepackage{minted}
\nofiles
\pagestyle{empty}
\setlength{\parindent}{0in}
\begin{document}
\noindent {\sc {\bf {\Large Quiz 2 - practice questions}}
\hfill EML4930/6934, Python Programming, Fall 2017}
\bigskip
\noindent {\sc {}
\hfill {\large Name:}
\hfill}
\bigskip
The real quiz will have three questions similar to the ones below.
\begin{enumerate}
\item Consider an object named a. What is one way to list all of the attributes (and methods) within the object a?
\item How would you take the square root of 63.1516 in Python? (if you use a library you must stat the correct import)
\item Consider a list name x that already contains a lot of information. Consider a list y = ['bob', 'loves Python', 87289]. How would you add y to the end of list x?
\item z is a high dimensional numpy array. How would you find the index location of the maximum value of z?
\item Code a:
\begin{minted}
{python}
import numpy as np
x = np.random.random(100000)
y = []
for i in x:
y.append(2.0*x)
y = np.array(y)
\end{minted}
Code b:
\begin{minted}
{python}
import numpy as np
x = np.random.random(100000)
y = 2.0*x
\end{minted}
Code a and code b do the exact same thing. Which code will run faster? (a, b, or both will run the same speed) Why?
\item Your friend is new to Python and programming. He is running the following code:
\begin{minted}
{python}
from __future__ import division
import numpy as np
x = np.ones(10, dtype='int')
y = np.random.random(10)
for i in range(10):
x[i] = y[i]/2.0
\end{minted}
but he keeps getting that x = array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]). Why is each item in x zero?
\item given
x = np.array([[4.0, 2.0],[-2.0,3.0]])
How would you transpose x?
\item Write out the values in z
\begin{minted}
{python}
x = np.array([[4.0, 2.0],
[-2.0,3.0]])
y = np.array([[2.0, 1.0],
[0.0, 1.0])
z = x*y
\end{minted}
\item Consider the following matrix multiplication
\begin{equation}
\begin{bmatrix}
2 & 3 \\
1 & 0 \\
\end{bmatrix}\begin{bmatrix}
5 & 2 \\
1 & 3 \\
\end{bmatrix}\begin{bmatrix}
1 & 0 \\
2 & 0 \\
\end{bmatrix} = z
\end{equation} Write out all the code (including imports) to solve for z in Python.
\item Plot the function
\begin{equation}
y(x) = x^3 + 2x + 10.0
\end{equation} on the domain \begin{equation}
10 \leq x \leq 19
\end{equation} using Python. Include all necessary imported libraries.
\end{enumerate}
%{\bf Problem 1.}(10 points.) The surface area of a sphere is increasing at a rate of 2 $\frac{\text{cm}^2}{\text{s}}$. Fine the rate at which the radius is increasing when the radius is $10$ cm.
%
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%{\bf Problem 2.}(10 points.) State what is the meaning of life.
%
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
%\bigskip
\end{document}