Skip to content
Snippets Groups Projects
Commit 85ed9896 authored by Jennifer Rinker's avatar Jennifer Rinker
Browse files

initial upload of demo notebook

parent a18269ae
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
Jupyter notebooks are extremely cool ways to demo your code or work interactively. They are separated into cells, just like Mathematica. You enter insert mode by clicking "enter" when a cell is selected, and you exit by hitting the escape key. You evaluate a cell using shift-enter.
%% Cell type:markdown id: tags:
# Cell types
%% Cell type:markdown id: tags:
You can control the type of cell in Cell -> Cell Type, and choose whether your cell is
- text
- code
Text cells can be formatted following Markdown conventions.
%% Cell type:markdown id: tags:
# Random cool things
%% Cell type:code id: tags:
``` python
x = 'Hello, world!'
```
%% Cell type:markdown id: tags:
Note that the output of a cell in the last line is automatically printed if it's a variable or unassigned output:
%% Cell type:code id: tags:
``` python
x = 4
2 * x
```
%% Output
8
%% Cell type:markdown id: tags:
There are a bunch of "magic" commands that can really up your game.
%% Cell type:code id: tags:
``` python
%lsmagic
```
%% Output
Available line magics:
%alias %alias_magic %autocall %automagic %autosave %bookmark %cd %clear %cls %colors %config %connect_info %copy %ddir %debug %dhist %dirs %doctest_mode %echo %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %macro %magic %matplotlib %mkdir %more %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %popd %pprint %precision %profile %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %ren %rep %rerun %reset %reset_selective %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode
Available cell magics:
%%! %%HTML %%SVG %%bash %%capture %%cmd %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile
Automagic is ON, % prefix IS NOT needed for line magics.
%% Cell type:markdown id: tags:
For example, let's test how long a silly function takes...
%% Cell type:code id: tags:
``` python
import numpy as np
def silly_function():
np.random.randint(0, high=100, size=int(1e6))
```
%% Cell type:code id: tags:
``` python
%%timeit
silly_function()
```
%% Output
1.7 ms ± 19.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
%% Cell type:markdown id: tags:
# Exercise
%% Cell type:markdown id: tags:
Define $x$ and $y$ below such that $x$ is a numpy array from 1 to 9 (inclusive) and $y=1/x$. Then, run your cell and the next cell and look at the resulting plot. Does it make sense? Run your mouse over the plot. Notice anything cool?
__HINT__: Google "numpy arange function" to figure out how to define $x$.
%% Cell type:code id: tags:
``` python
import numpy as np
# x = ???
# y = ???
```
%% Cell type:code id: tags:
``` python
import plotly
from plotly.graph_objs import Scatter, Layout
plotly.offline.init_notebook_mode(connected=True)
plotly.offline.iplot({
"data": [Scatter(x=x, y=y)],
"layout": Layout(title="Hello, world!")
})
```
%% Cell type:markdown id: tags:
# Solution
%% Cell type:code id: tags:
``` python
import numpy as np
x = np.arange(1, 10)
y = 1/x
```
%% Cell type:code id: tags:
``` python
import plotly
from plotly.graph_objs import Scatter, Layout
plotly.offline.init_notebook_mode(connected=True)
plotly.offline.iplot({
"data": [Scatter(x=x, y=y)],
"layout": Layout(title="Hello, world!")
})
```
%% Output
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment