|
15 | 15 | },
|
16 | 16 | "outputs": [],
|
17 | 17 | "source": [
|
| 18 | + "from __future__ import print_function\n", |
18 | 19 | "import tensorflow as tf\n",
|
19 | 20 | "import numpy as np"
|
20 | 21 | ]
|
|
27 | 28 | },
|
28 | 29 | "outputs": [
|
29 | 30 | {
|
30 |
| - "name": "stdout", |
31 |
| - "output_type": "stream", |
32 |
| - "text": [ |
33 |
| - "0.10.0\n", |
34 |
| - "1.11.1\n" |
35 |
| - ] |
| 31 | + "data": { |
| 32 | + "text/plain": [ |
| 33 | + "datetime.date(2017, 2, 22)" |
| 34 | + ] |
| 35 | + }, |
| 36 | + "execution_count": 2, |
| 37 | + "metadata": {}, |
| 38 | + "output_type": "execute_result" |
36 | 39 | }
|
37 | 40 | ],
|
38 | 41 | "source": [
|
39 |
| - "print tf.__version__\n", |
40 |
| - "print np.__version__" |
| 42 | + "from datetime import date\n", |
| 43 | + "date.today()" |
41 | 44 | ]
|
42 | 45 | },
|
43 | 46 | {
|
|
48 | 51 | },
|
49 | 52 | "outputs": [],
|
50 | 53 | "source": [
|
51 |
| - "sess = tf.InteractiveSession()" |
| 54 | + "author = \"kyubyong. https://github.com/Kyubyong/tensorflow-exercises\"" |
52 | 55 | ]
|
53 | 56 | },
|
54 | 57 | {
|
55 |
| - "cell_type": "markdown", |
56 |
| - "metadata": {}, |
| 58 | + "cell_type": "code", |
| 59 | + "execution_count": 4, |
| 60 | + "metadata": { |
| 61 | + "collapsed": false |
| 62 | + }, |
| 63 | + "outputs": [ |
| 64 | + { |
| 65 | + "data": { |
| 66 | + "text/plain": [ |
| 67 | + "'1.0.0'" |
| 68 | + ] |
| 69 | + }, |
| 70 | + "execution_count": 4, |
| 71 | + "metadata": {}, |
| 72 | + "output_type": "execute_result" |
| 73 | + } |
| 74 | + ], |
57 | 75 | "source": [
|
58 |
| - "Q1. Let x and y be random 0-D tensors. Return x + y \n", |
59 |
| - "if x < y and x - y otherwise." |
| 76 | + "tf.__version__" |
60 | 77 | ]
|
61 | 78 | },
|
62 | 79 | {
|
63 | 80 | "cell_type": "code",
|
64 |
| - "execution_count": 37, |
| 81 | + "execution_count": 5, |
65 | 82 | "metadata": {
|
66 | 83 | "collapsed": false
|
67 | 84 | },
|
68 | 85 | "outputs": [
|
69 | 86 | {
|
70 |
| - "name": "stdout", |
71 |
| - "output_type": "stream", |
72 |
| - "text": [ |
73 |
| - "0.469627\n" |
74 |
| - ] |
| 87 | + "data": { |
| 88 | + "text/plain": [ |
| 89 | + "'1.12.0'" |
| 90 | + ] |
| 91 | + }, |
| 92 | + "execution_count": 5, |
| 93 | + "metadata": {}, |
| 94 | + "output_type": "execute_result" |
75 | 95 | }
|
76 | 96 | ],
|
77 |
| - "source": [] |
| 97 | + "source": [ |
| 98 | + "np.__version__" |
| 99 | + ] |
| 100 | + }, |
| 101 | + { |
| 102 | + "cell_type": "code", |
| 103 | + "execution_count": 6, |
| 104 | + "metadata": { |
| 105 | + "collapsed": true |
| 106 | + }, |
| 107 | + "outputs": [], |
| 108 | + "source": [ |
| 109 | + "sess = tf.InteractiveSession()" |
| 110 | + ] |
78 | 111 | },
|
79 | 112 | {
|
80 | 113 | "cell_type": "markdown",
|
81 | 114 | "metadata": {},
|
82 | 115 | "source": [
|
83 |
| - "Q2. Let x and y be 0-D int tensors randomly selected from 0 to 5. Return x + y 2 if x < y, x - y elif x > y, 0 otherwise." |
| 116 | + "NOTE on notation\n", |
| 117 | + "* _x, _y, _z, ...: NumPy 0-d or 1-d arrays\n", |
| 118 | + "* _X, _Y, _Z, ...: NumPy 2-d or higer dimensional arrays\n", |
| 119 | + "* x, y, z, ...: 0-d or 1-d tensors\n", |
| 120 | + "* X, Y, Z, ...: 2-d or higher dimensional tensors" |
| 121 | + ] |
| 122 | + }, |
| 123 | + { |
| 124 | + "cell_type": "markdown", |
| 125 | + "metadata": {}, |
| 126 | + "source": [ |
| 127 | + "## Control Flow Operations" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "markdown", |
| 132 | + "metadata": {}, |
| 133 | + "source": [ |
| 134 | + "Q1. Let x and y be random 0-D tensors. Return x + y \n", |
| 135 | + "if x < y and x - y otherwise." |
84 | 136 | ]
|
85 | 137 | },
|
86 | 138 | {
|
87 | 139 | "cell_type": "code",
|
88 |
| - "execution_count": 11, |
| 140 | + "execution_count": 7, |
89 | 141 | "metadata": {
|
90 | 142 | "collapsed": false
|
91 | 143 | },
|
|
94 | 146 | "name": "stdout",
|
95 | 147 | "output_type": "stream",
|
96 | 148 | "text": [
|
97 |
| - "1\n" |
| 149 | + "1.75876\n", |
| 150 | + "0.9915587370245782\n" |
98 | 151 | ]
|
99 | 152 | }
|
100 | 153 | ],
|
|
104 | 157 | "cell_type": "markdown",
|
105 | 158 | "metadata": {},
|
106 | 159 | "source": [
|
107 |
| - "Q3. Let x be a tensor [[-1, -2, -3], [0, 1, 2]] and y be a tensor of zeros with the same shape as x. Return a boolean tensor that yields Trues if x equals y elementwise." |
| 160 | + "Q2. Let x and y be 0-D int32 tensors randomly selected from 0 to 5. Return x + y 2 if x < y, x - y elif x > y, 0 otherwise." |
108 | 161 | ]
|
109 | 162 | },
|
110 | 163 | {
|
111 | 164 | "cell_type": "code",
|
112 |
| - "execution_count": 44, |
| 165 | + "execution_count": 8, |
113 | 166 | "metadata": {
|
114 | 167 | "collapsed": false
|
115 | 168 | },
|
|
118 | 171 | "name": "stdout",
|
119 | 172 | "output_type": "stream",
|
120 | 173 | "text": [
|
121 |
| - "[[False False False]\n", |
122 |
| - " [ True False False]]\n" |
| 174 | + "1\n", |
| 175 | + "1\n" |
123 | 176 | ]
|
124 | 177 | }
|
125 | 178 | ],
|
|
129 | 182 | "cell_type": "markdown",
|
130 | 183 | "metadata": {},
|
131 | 184 | "source": [
|
132 |
| - "Q4. Let x be a tensor [[-1, -2, -3], [0, 1, 2]] and y be a tensor of zeros with the same shape as x. Return a boolean tensor that yields Trues if x does not equal y elementwise." |
| 185 | + "Q3. Let X be a tensor [[-1, -2, -3], [0, 1, 2]] and Y be a tensor of zeros with the same shape as X. Return a boolean tensor that yields True if X equals Y elementwise." |
133 | 186 | ]
|
134 | 187 | },
|
135 | 188 | {
|
136 | 189 | "cell_type": "code",
|
137 |
| - "execution_count": 45, |
| 190 | + "execution_count": 9, |
138 | 191 | "metadata": {
|
139 | 192 | "collapsed": false
|
140 | 193 | },
|
|
143 | 196 | "name": "stdout",
|
144 | 197 | "output_type": "stream",
|
145 | 198 | "text": [
|
146 |
| - "[[ True True True]\n", |
147 |
| - " [False True True]]\n" |
| 199 | + "[[False False False]\n", |
| 200 | + " [ True False False]]\n" |
148 | 201 | ]
|
149 | 202 | }
|
150 | 203 | ],
|
|
154 | 207 | "cell_type": "markdown",
|
155 | 208 | "metadata": {},
|
156 | 209 | "source": [
|
157 |
| - "Q5. Let x be a tensor [[-1, -2, -3], [0, 1, 2]] and y be a tensor of zeros with the same shape as x. Return a boolean tensor that yields Trues if x is greater than or equal to y elementwise." |
| 210 | + "## Logical Operators" |
| 211 | + ] |
| 212 | + }, |
| 213 | + { |
| 214 | + "cell_type": "markdown", |
| 215 | + "metadata": {}, |
| 216 | + "source": [ |
| 217 | + "Q4. Given x and y below, return the truth value x AND/OR/XOR y element-wise." |
158 | 218 | ]
|
159 | 219 | },
|
160 | 220 | {
|
161 | 221 | "cell_type": "code",
|
162 |
| - "execution_count": 46, |
| 222 | + "execution_count": 10, |
163 | 223 | "metadata": {
|
164 | 224 | "collapsed": false
|
165 | 225 | },
|
|
168 | 228 | "name": "stdout",
|
169 | 229 | "output_type": "stream",
|
170 | 230 | "text": [
|
171 |
| - "[[False False False]\n", |
172 |
| - " [ True True True]]\n" |
| 231 | + "[ True False False] [ True True False] [False True False]\n" |
173 | 232 | ]
|
174 | 233 | }
|
175 | 234 | ],
|
176 |
| - "source": [] |
| 235 | + "source": [ |
| 236 | + "x = tf.constant([True, False, False], tf.bool)\n", |
| 237 | + "y = tf.constant([True, True, False], tf.bool)\n" |
| 238 | + ] |
177 | 239 | },
|
178 | 240 | {
|
179 | 241 | "cell_type": "markdown",
|
180 | 242 | "metadata": {},
|
181 | 243 | "source": [
|
182 |
| - "Q6. Let x be a tensor [[-1, -2, -3], [0, 1, 2]] and y be a tensor of zeros with the same shape as x. Return a boolean tensor that yields Trues if x is less than or equal to y elementwise.\n" |
| 244 | + "Q5. Given x, return the truth value of NOT x element-wise." |
183 | 245 | ]
|
184 | 246 | },
|
185 | 247 | {
|
186 | 248 | "cell_type": "code",
|
187 |
| - "execution_count": 47, |
| 249 | + "execution_count": 11, |
188 | 250 | "metadata": {
|
189 | 251 | "collapsed": false
|
190 | 252 | },
|
|
193 | 255 | "name": "stdout",
|
194 | 256 | "output_type": "stream",
|
195 | 257 | "text": [
|
196 |
| - "[[ True True True]\n", |
197 |
| - " [ True False False]]\n" |
| 258 | + "[False True True]\n" |
198 | 259 | ]
|
199 | 260 | }
|
200 | 261 | ],
|
201 |
| - "source": [] |
| 262 | + "source": [ |
| 263 | + "x = tf.constant([True, False, False], tf.bool)\n" |
| 264 | + ] |
| 265 | + }, |
| 266 | + { |
| 267 | + "cell_type": "markdown", |
| 268 | + "metadata": {}, |
| 269 | + "source": [ |
| 270 | + "## Comparison Operators" |
| 271 | + ] |
202 | 272 | },
|
203 | 273 | {
|
204 | 274 | "cell_type": "markdown",
|
205 | 275 | "metadata": {},
|
206 | 276 | "source": [
|
207 |
| - "Q7. Let x be a 0-D tensor randomly selected from -5 to 5. Return a boolean tensor that yields Trues if x is less than 3 and x is greater than 0.\n" |
| 277 | + "Q6. Let X be a tensor [[-1, -2, -3], [0, 1, 2]] and Y be a tensor of zeros with the same shape as x. Return a boolean tensor that yields True if X does not equal Y elementwise." |
208 | 278 | ]
|
209 | 279 | },
|
210 | 280 | {
|
211 | 281 | "cell_type": "code",
|
212 |
| - "execution_count": 49, |
| 282 | + "execution_count": 12, |
213 | 283 | "metadata": {
|
214 | 284 | "collapsed": false
|
215 | 285 | },
|
|
218 | 288 | "name": "stdout",
|
219 | 289 | "output_type": "stream",
|
220 | 290 | "text": [
|
221 |
| - "True\n" |
| 291 | + "[[ True True True]\n", |
| 292 | + " [False True True]]\n" |
222 | 293 | ]
|
223 | 294 | }
|
224 | 295 | ],
|
|
228 | 299 | "cell_type": "markdown",
|
229 | 300 | "metadata": {},
|
230 | 301 | "source": [
|
231 |
| - "Q8. Let x be a tensor [[1, 2], [3, 4]], y be a tensor [[5, 6], [7, 8]], and z be a boolean tensor [[True, False], [False, True]]. Create a 2*2 tensor such that each element corresponds to x if True, otherise y." |
| 302 | + "Q7. Let X be a tensor [[-1, -2, -3], [0, 1, 2]] and Y be a tensor of zeros with the same shape as X. Return a boolean tensor that yields True if X is greater than or equal to Y elementwise." |
232 | 303 | ]
|
233 | 304 | },
|
234 | 305 | {
|
235 | 306 | "cell_type": "code",
|
236 |
| - "execution_count": 51, |
| 307 | + "execution_count": 13, |
237 | 308 | "metadata": {
|
238 | 309 | "collapsed": false
|
239 | 310 | },
|
|
242 | 313 | "name": "stdout",
|
243 | 314 | "output_type": "stream",
|
244 | 315 | "text": [
|
245 |
| - "[[1 6]\n", |
246 |
| - " [7 4]]\n" |
| 316 | + "[[False False False]\n", |
| 317 | + " [ True True True]]\n" |
247 | 318 | ]
|
248 | 319 | }
|
249 | 320 | ],
|
|
253 | 324 | "cell_type": "markdown",
|
254 | 325 | "metadata": {},
|
255 | 326 | "source": [
|
256 |
| - "Q9. Let x be a tensor [1, 2, 3, ..., 100]. Extract elements of x greater than 30." |
| 327 | + "Q8. Let X be a tensor [[1, 2], [3, 4]], Y be a tensor [[5, 6], [7, 8]], and Z be a boolean tensor [[True, False], [False, True]]. Create a 2*2 tensor such that each element corresponds to X if Z is True, otherise Y." |
257 | 328 | ]
|
258 | 329 | },
|
259 | 330 | {
|
260 | 331 | "cell_type": "code",
|
261 |
| - "execution_count": 75, |
| 332 | + "execution_count": 14, |
262 | 333 | "metadata": {
|
263 | 334 | "collapsed": false
|
264 | 335 | },
|
|
267 | 338 | "name": "stdout",
|
268 | 339 | "output_type": "stream",
|
269 | 340 | "text": [
|
270 |
| - "[ 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48\n", |
271 |
| - " 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66\n", |
272 |
| - " 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84\n", |
273 |
| - " 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100]\n" |
| 341 | + "[[1 6]\n", |
| 342 | + " [7 4]]\n" |
274 | 343 | ]
|
275 | 344 | }
|
276 | 345 | ],
|
277 |
| - "source": [] |
| 346 | + "source": [ |
| 347 | + "\n" |
| 348 | + ] |
278 | 349 | },
|
279 | 350 | {
|
280 | 351 | "cell_type": "code",
|
|
287 | 358 | }
|
288 | 359 | ],
|
289 | 360 | "metadata": {
|
| 361 | + "anaconda-cloud": {}, |
290 | 362 | "kernelspec": {
|
291 |
| - "display_name": "Python 2", |
| 363 | + "display_name": "Python [conda root]", |
292 | 364 | "language": "python",
|
293 |
| - "name": "python2" |
| 365 | + "name": "conda-root-py" |
294 | 366 | },
|
295 | 367 | "language_info": {
|
296 | 368 | "codemirror_mode": {
|
297 | 369 | "name": "ipython",
|
298 |
| - "version": 2 |
| 370 | + "version": 3 |
299 | 371 | },
|
300 | 372 | "file_extension": ".py",
|
301 | 373 | "mimetype": "text/x-python",
|
302 | 374 | "name": "python",
|
303 | 375 | "nbconvert_exporter": "python",
|
304 |
| - "pygments_lexer": "ipython2", |
305 |
| - "version": "2.7.6" |
| 376 | + "pygments_lexer": "ipython3", |
| 377 | + "version": "3.5.2" |
306 | 378 | }
|
307 | 379 | },
|
308 | 380 | "nbformat": 4,
|
|
0 commit comments