<jupyter_start><jupyter_text>IPython  1. Extremely useful  rows begin with ! executed in bash<jupyter_code>!ls
!top<jupyter_output><empty_output><jupyter_text>%who prints all variables<jupyter_code>a=b=c=1

%who<jupyter_output><empty_output><jupyter_text>placing a ? after object will give documentation (docstring)<jupyter_code>print?<jupyter_output><empty_output><jupyter_text>2. Magic Commands  show all magic commands<jupyter_code>%lsmagic<jupyter_output><empty_output><jupyter_text>enable plotting inside notebook<jupyter_code>%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>%timeit magic measures execution time. It exists both in line and cell form<jupyter_code>%timeit np.linalg.eigvals(np.random.rand(100,100))
%%timeit a = np.random.rand(100, 100)
np.linalg.eigvals(a)<jupyter_output><empty_output><jupyter_text>The %%capture magic can be used to capture the stdout/err of any block of python code, either to discard it (if it's noise to you) or to store it in a variable for later use:<jupyter_code>%%capture capt
from __future__ import print_function
import sys
print('Hello stdout')
print('and stderr', file=sys.stderr)
capt.stdout, capt.stderr<jupyter_output><empty_output><jupyter_text>The %%writefile magic is a very useful tool that writes the cell contents as a named file:<jupyter_code>%%writefile foo.py
print('Hello world')<jupyter_output><empty_output><jupyter_text>%run let's your run python scripts<jupyter_code>%run foo<jupyter_output><empty_output><jupyter_text>%%bash runs on linux bash<jupyter_code>%%bash
echo "hello from $BASH"<jupyter_output><empty_output><jupyter_text>3. Rich Output  Visualize a photo in notebook<jupyter_code>from IPython.display import Image
Image(filename='data/logo-ensae.jpg')<jupyter_output><empty_output><jupyter_text>Or put the photo inside a markdown![figure](data/logo-ensae.jpg)  Write HTML<jupyter_code>from IPython.display import HTML

s = """<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>"""

HTML(s)<jupyter_output><empty_output><jupyter_text>Write Javascript<jupyter_code>%%javascript

alert("hi");<jupyter_output><empty_output><jupyter_text>Write LaTex<jupyter_code>from IPython.display import Math
Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')<jupyter_output><empty_output><jupyter_text>Play wave<jupyter_code>from IPython.display import Audio
Audio(url="http://www.slinkycity.com/u4r/arnie.wav")<jupyter_output><empty_output><jupyter_text>Play YouTube video<jupyter_code>from IPython.display import YouTubeVideo
YouTubeVideo('QgaRd4d8hOY')
from IPython.display import IFrame
IFrame('http://ensae.fr', width='100%', height=350)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup