Notebooks#

Jupyter Notebook#

Markdown

Preview

**bold text**

bold text

*italicized text* or _italicized text_

italicized text

`Monospace`

Monospace

~~strikethrough~~

[STRIKEOUT:strikethrough]

[A link](https://www.google.com)

A link

![An image](https://www.google.com/images/rss.png)

An image

[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com)

Open In Colab

Colored Note Boxes#

  • Blue Boxes (alert-info)

<div class="alert alert-block alert-info">
<b>Tip:</b> Use blue boxes (alert-info) for tips and notes.
If it’s a note, you don’t have to include the word “Note”.
</div>

Tip: Use blue boxes (alert-info) for tips and notes. If it’s a note, you don’t have to include the word “Note”.

  • Yellow Boxes (alert-warning)

<div class="alert alert-block alert-warning">
<b>Example:</b> Use yellow boxes for examples that are not
inside code cells, or use for mathematical formulas if needed.
</div>

Example: Use yellow boxes for examples that are not inside code cells, or use for mathematical formulas if needed.

  • Green Boxes (alert-success)

<div class="alert alert-block alert-success">
<b>Up to you:</b> Use green boxes sparingly, and only for some specific
purpose that the other boxes can't cover. For example, if you have a lot
of related content to link to, maybe you decide to use green boxes for
related links from each section of a notebook.
</div>

Up to you: Use green boxes sparingly, and only for some specific purpose that the other boxes can’t cover. For example, if you have a lot of related content to link to, maybe you decide to use green boxes for related links from each section of a notebook.

  • Red Boxes (alert-danger)

<div class="alert alert-block alert-danger">
<b>Just don't:</b> In general, avoid the red boxes. These should only be
used for actions that might cause data loss or another major issue.
</div>

Just don’t: In general, avoid the red boxes. These should only be used for actions that might cause data loss or another major issue.

Magics#

  • List all cell/line magics

%lsmagic
  • Writes the cell contents as a named file

%%writefile foo.py
print('Hello world')
  • Run a python file

%run foo
[1]:
import numpy as np
[2]:
%alias_magic t time
%precision 3
Created `%t` as an alias for `%time`.
Created `%%t` as an alias for `%%time`.
[2]:
'%.3f'
[3]:
%%t
a = 3000
b = '100'
c = int(b)
d = np.linalg.inv(np.random.random((a,a)))
%timeit -n100 np.linalg.inv(np.random.random((c,c)))
1.37 ms ± 63.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
CPU times: total: 7.61 s
Wall time: 1.39 s
[4]:
%whos
%xdel d
%whos
Variable   Type       Data/Info
-------------------------------
a          int        3000
b          str        100
c          int        100
d          ndarray    3000x3000: 9000000 elems, type `float64`, 72000000 bytes (68.66455078125 Mb)
np         module     <module 'numpy' from 'C:\<...>ges\\numpy\\__init__.py'>
Variable   Type      Data/Info
------------------------------
a          int       3000
b          str       100
c          int       100
np         module    <module 'numpy' from 'C:\<...>ges\\numpy\\__init__.py'>
[5]:
# %load_ext rpy2.ipython

References#