https://github.com/powerpak/jupyter-dark-theme
mkdir -p ~/.jupyter/custom
wget https://github.com/powerpak/jupyter-dark-theme/raw/master/custom.css \
-O ~/.jupyter/custom/custom.css
2 + 2
_**4
import math
math.log2(_2)
import sympy
sympy.init_printing(use_latex='mathjax')
x = sympy.symbols('x')
x**2 / 3 + 1
sympy.solve(_, x)
print(sympy.latex(_5))
$\LaTeX$ works in markdown cells too: $\frac{x^{2}}{3} + 1$
str.is*?
str.isalnum?
!screenfetch
lines = !ls -l
lines
/print lines.n
lines.s
lines.grep('ipynb')
lines.grep('ipynb').fields(-1)
lines.grep('ipynb').fields(-1).p
for p in lines.grep('ipynb').fields(-1).p:
!echo $p.suffix {p.suffix.lstrip('.')}
for s, p in map(str.split, lines.grep('ipynb').fields(4, -1)):
du = !du -sh $p
!echo {du.fields(0).s} $s {du.fields(1).s}
!echo $USER
%store lines
%store
from collections import deque
def fib(n):
"""
>>> fib(10)
[0, 1, 2, 3, 5, 8, 13, 21, 34, 55]
"""
q = deque([0, 1], 2)
return [q.append(sum(q)) or q[0] for i in range(2, n + 2)]
import doctest
doctest.run_docstring_examples(fib, None)
%time fib(10)
%timeit fib(10)
%prun fib(10)
%load_ext line_profiler
%lprun -f fib fib(10)
Requires line_profiler
package.
Requires ipython-sql
package.
%load_ext sql
%%sql sqlite://
CREATE TABLE data (a, b);
INSERT INTO data VALUES
('a', 1),
('b', 2),
('c', 3),
('d', 4),
('e', 5),
('f', 6);
%sql select * from data
v = 3
%sql select * from data where b = :v
data = %sql select * from data
data.DataFrame().query('b > 3')
%matplotlib inline
import matplotlib as mpl
mpl.style.use('seaborn-darkgrid')
mpl.rc('figure', figsize=(12, 8))
mpl.rc('font', size=18)
data.bar();
data.pie();
Requires ipywidgets
packages:
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension
from ipywidgets import interactive
import matplotlib.pyplot as plt
import numpy as np
def f(m, b):
plt.figure(2)
x = np.linspace(-10, 10, num=100)
plt.axhline(0, color='gray')
plt.axvline(0, color='gray')
plt.plot(x, m * x + b, linewidth=3)
plt.ylim(-5, 5)
plt.show()
interactive(f, m=(-2.0, 2.0), b=(-3, 3, 0.5))
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.animation as animation
mpl.rc('animation', html='html5')
fig, ax = plt.subplots(figsize=(5, 5))
x = np.linspace(-10, 10, num=100)
b = np.sin(np.linspace(-np.pi, np.pi, 200))
ax.axhline(0, color='gray')
ax.axvline(0, color='gray')
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
line, = ax.plot([], [], lw=3)
plt.close()
def update(b):
line.set_data(x, b * x)
return line,
animation.FuncAnimation(fig, update, frames=b, interval=24)