|
20 | 20 | "source": [ |
21 | 21 | "````{note}\n", |
22 | 22 | " \n", |
23 | | - "Note that the traditional way to import numpy is to rename it np. This saves on typing and makes your code a little more compact.\n", |
| 23 | + "Note that the traditional way to import numpy is to rename it `np`. This saves on typing and makes your code a little more compact.\n", |
24 | 24 | "````" |
25 | 25 | ] |
26 | 26 | }, |
|
205 | 205 | "cell_type": "markdown", |
206 | 206 | "metadata": {}, |
207 | 207 | "source": [ |
208 | | - "<div class=\"alert alert-block alert-warning\">\n", |
209 | | - " \n", |
210 | | - "<span class=\"fa fa-flash\"></span> Quick Exercise:\n", |
| 208 | + "````{admonition} Quick Exercise\n", |
211 | 209 | "\n", |
212 | 210 | "Analogous to `linspace()`, there is a `logspace()` function that creates an array with elements equally spaced in log. Use `help(np.logspace)` to see the arguments, and create an array with 10 elements from $10^{-6}$ to $10^3$.\n", |
213 | 211 | "\n", |
214 | | - "</div>" |
| 212 | + "````" |
215 | 213 | ] |
216 | 214 | }, |
217 | 215 | { |
|
303 | 301 | "cell_type": "markdown", |
304 | 302 | "metadata": {}, |
305 | 303 | "source": [ |
306 | | - "<div class=\"alert alert-block alert-warning\">\n", |
307 | | - " \n", |
308 | | - "<span class=\"fa fa-flash\"></span> Quick Exercise:\n", |
| 304 | + "````{admonition} Quick Exercise\n", |
309 | 305 | "\n", |
310 | 306 | "What do you think `1./a` will do? Try it and see\n", |
311 | 307 | "\n", |
312 | | - "</div>" |
| 308 | + "````" |
313 | 309 | ] |
314 | 310 | }, |
315 | 311 | { |
|
372 | 368 | "cell_type": "markdown", |
373 | 369 | "metadata": {}, |
374 | 370 | "source": [ |
375 | | - "<div class=\"alert alert-block alert-warning\">\n", |
376 | | - " \n", |
377 | | - "<span class=\"fa fa-flash\"></span> Quick Exercise:\n", |
| 371 | + "````{admonition} Quick Exercise\n", |
378 | 372 | "\n", |
379 | 373 | "`sum()` takes an optional argument, `axis=N`, where `N` is the axis to sum over. Sum the elements of `a` across rows to create an array with just the sum along each column of `a`.\n", |
380 | 374 | "\n", |
381 | | - "</div>" |
| 375 | + "````" |
382 | 376 | ] |
383 | 377 | }, |
384 | 378 | { |
|
460 | 454 | "cell_type": "markdown", |
461 | 455 | "metadata": {}, |
462 | 456 | "source": [ |
463 | | - "<div class=\"alert alert-block alert-warning\">\n", |
464 | | - " \n", |
465 | | - "<span class=\"fa fa-flash\"></span> Quick Exercise:\n", |
| 457 | + "````{admonition} Quick Exercise\n", |
466 | 458 | "\n", |
467 | 459 | "We will often want to write our own function that operates on an array and returns a new array. We can do this just like we did with functions previously—the key is to use the methods from the `np` module to do any operations, since they work on, and return, arrays.\n", |
468 | 460 | "\n", |
469 | 461 | "Write a simple function that returns $\\sin(2\\pi x)$ for an input array `x`. Then test it \n", |
470 | 462 | "by passing in an array `x` that you create via `linspace()`\n", |
471 | 463 | "\n", |
472 | | - "</div>" |
| 464 | + "````" |
473 | 465 | ] |
474 | 466 | }, |
475 | 467 | { |
|
739 | 731 | "cell_type": "markdown", |
740 | 732 | "metadata": {}, |
741 | 733 | "source": [ |
742 | | - "<div class=\"alert alert-block alert-warning\">\n", |
743 | | - " \n", |
744 | | - "<span class=\"fa fa-flash\"></span> Quick Exercise:\n", |
| 734 | + "````{admonition} Quick Exercise\n", |
745 | 735 | "\n", |
746 | 736 | "Consider the array defined as:\n", |
747 | 737 | "\n", |
|
758 | 748 | " * using slice notation, create an array that consists of only the `4`'s in `q` (this will be called a _view_, as we'll see shortly)\n", |
759 | 749 | " * zero out all of the elements in your view\n", |
760 | 750 | " * how does `q` change?\n", |
761 | | - "</dov> " |
| 751 | + "````" |
762 | 752 | ] |
763 | 753 | }, |
764 | 754 | { |
|
1205 | 1195 | "metadata": {}, |
1206 | 1196 | "source": [ |
1207 | 1197 | "Now we want to construct a derivative, \n", |
| 1198 | + "\n", |
1208 | 1199 | "$$\n", |
1209 | 1200 | "\\frac{d f}{dx}\n", |
1210 | 1201 | "$$" |
|
1225 | 1216 | "metadata": {}, |
1226 | 1217 | "source": [ |
1227 | 1218 | "We want to do this without loops—we'll use views into arrays offset from one another. Recall from calculus that a derivative is approximately:\n", |
| 1219 | + "\n", |
1228 | 1220 | "$$\n", |
1229 | 1221 | "\\frac{df}{dx} = \\frac{f(x+h) - f(x)}{h}\n", |
1230 | 1222 | "$$\n", |
| 1223 | + "\n", |
1231 | 1224 | "Here, we'll take $h$ to be a single adjacent element" |
1232 | 1225 | ] |
1233 | 1226 | }, |
|
1249 | 1242 | "source": [ |
1250 | 1243 | "dfdx" |
1251 | 1244 | ] |
1252 | | - }, |
1253 | | - { |
1254 | | - "cell_type": "code", |
1255 | | - "execution_count": null, |
1256 | | - "metadata": {}, |
1257 | | - "outputs": [], |
1258 | | - "source": [] |
1259 | 1245 | } |
1260 | 1246 | ], |
1261 | 1247 | "metadata": { |
|
0 commit comments