Skip to content

Commit

Permalink
Make more cells markdown instead of raw
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Sep 28, 2017
1 parent 4323f2a commit 264111f
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 184 deletions.
50 changes: 33 additions & 17 deletions appa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -634,19 +634,21 @@
]
},
{
"cell_type": "raw",
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"```python\n",
"def demean_axis(arr, axis=0):\n",
" means = arr.mean(axis)\n",
"\n",
" # This generalizes things like [:, :, np.newaxis] to N dimensions\n",
" indexer = [slice(None)] * arr.ndim\n",
" indexer[axis] = np.newaxis\n",
" return arr - means[indexer]"
" return arr - means[indexer]\n",
"```"
]
},
{
Expand Down Expand Up @@ -1342,12 +1344,13 @@
]
},
{
"cell_type": "raw",
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"```python\n",
"In [209]: x = np.random.randn(10000000)\n",
"\n",
"In [210]: y = np.random.randn(10000000)\n",
Expand All @@ -1356,28 +1359,32 @@
"1 loop, best of 3: 2 s per loop\n",
"\n",
"In [212]: %timeit (x - y).mean()\n",
"100 loops, best of 3: 14.7 ms per loop"
"100 loops, best of 3: 14.7 ms per loop\n",
"```"
]
},
{
"cell_type": "raw",
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"```python\n",
"In [213]: import numba as nb\n",
"\n",
"In [214]: numba_mean_distance = nb.jit(mean_distance)"
"In [214]: numba_mean_distance = nb.jit(mean_distance)\n",
"```"
]
},
{
"cell_type": "raw",
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"```python\n",
"@nb.jit\n",
"def mean_distance(x, y):\n",
" nx = len(x)\n",
Expand All @@ -1386,32 +1393,37 @@
" for i in range(nx):\n",
" result += x[i] - y[i]\n",
" count += 1\n",
" return result / count"
" return result / count\n",
"```"
]
},
{
"cell_type": "raw",
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"```python\n",
"In [215]: %timeit numba_mean_distance(x, y)\n",
"100 loops, best of 3: 10.3 ms per loop"
"100 loops, best of 3: 10.3 ms per loop\n",
"```"
]
},
{
"cell_type": "raw",
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"```python\n",
"from numba import float64, njit\n",
"\n",
"@njit(float64(float64[:], float64[:]))\n",
"def mean_distance(x, y):\n",
" return (x - y).mean()"
" return (x - y).mean()\n",
"```"
]
},
{
Expand All @@ -1425,33 +1437,37 @@
]
},
{
"cell_type": "raw",
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"```python\n",
"from numba import vectorize\n",
"\n",
"@vectorize\n",
"def nb_add(x, y):\n",
" return x + y"
" return x + y\n",
"```"
]
},
{
"cell_type": "raw",
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"```python\n",
"In [13]: x = np.arange(10)\n",
"\n",
"In [14]: nb_add(x, x)\n",
"Out[14]: array([ 0., 2., 4., 6., 8., 10., 12., 14., 16., 18.])\n",
"\n",
"In [15]: nb_add.accumulate(x, 0)\n",
"Out[15]: array([ 0., 1., 3., 6., 10., 15., 21., 28., 36., 45.])"
"Out[15]: array([ 0., 1., 3., 6., 10., 15., 21., 28., 36., 45.])\n",
"```"
]
},
{
Expand Down Expand Up @@ -1678,7 +1694,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
"version": "3.5.1"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 264111f

Please sign in to comment.