Skip to content

Commit

Permalink
more formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
zingale committed Jan 17, 2024
1 parent 32f1769 commit df65eac
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions content/02-numpy/numpy-basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"source": [
"````{note}\n",
" \n",
"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",
"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",
"````"
]
},
Expand Down Expand Up @@ -205,13 +205,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-warning\">\n",
" \n",
"<span class=\"fa fa-flash\"></span> Quick Exercise:\n",
"````{admonition} Quick Exercise\n",
"\n",
"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",
"\n",
"</div>"
"````"
]
},
{
Expand Down Expand Up @@ -303,13 +301,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-warning\">\n",
" \n",
"<span class=\"fa fa-flash\"></span> Quick Exercise:\n",
"````{admonition} Quick Exercise\n",
"\n",
"What do you think `1./a` will do? Try it and see\n",
"\n",
"</div>"
"````"
]
},
{
Expand Down Expand Up @@ -372,13 +368,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-warning\">\n",
" \n",
"<span class=\"fa fa-flash\"></span> Quick Exercise:\n",
"````{admonition} Quick Exercise\n",
"\n",
"`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",
"\n",
"</div>"
"````"
]
},
{
Expand Down Expand Up @@ -460,16 +454,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-warning\">\n",
" \n",
"<span class=\"fa fa-flash\"></span> Quick Exercise:\n",
"````{admonition} Quick Exercise\n",
"\n",
"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&mdash;the key is to use the methods from the `np` module to do any operations, since they work on, and return, arrays.\n",
"\n",
"Write a simple function that returns $\\sin(2\\pi x)$ for an input array `x`. Then test it \n",
"by passing in an array `x` that you create via `linspace()`\n",
"\n",
"</div>"
"````"
]
},
{
Expand Down Expand Up @@ -739,9 +731,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-warning\">\n",
" \n",
"<span class=\"fa fa-flash\"></span> Quick Exercise:\n",
"````{admonition} Quick Exercise\n",
"\n",
"Consider the array defined as:\n",
"\n",
Expand All @@ -758,7 +748,7 @@
" * 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",
" * zero out all of the elements in your view\n",
" * how does `q` change?\n",
"</dov> "
"````"
]
},
{
Expand Down Expand Up @@ -1205,6 +1195,7 @@
"metadata": {},
"source": [
"Now we want to construct a derivative, \n",
"\n",
"$$\n",
"\\frac{d f}{dx}\n",
"$$"
Expand All @@ -1225,9 +1216,11 @@
"metadata": {},
"source": [
"We want to do this without loops&mdash;we'll use views into arrays offset from one another. Recall from calculus that a derivative is approximately:\n",
"\n",
"$$\n",
"\\frac{df}{dx} = \\frac{f(x+h) - f(x)}{h}\n",
"$$\n",
"\n",
"Here, we'll take $h$ to be a single adjacent element"
]
},
Expand All @@ -1249,13 +1242,6 @@
"source": [
"dfdx"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit df65eac

Please sign in to comment.