In [ ]:
import math
print("The square root of 3 is:", math.sqrt(3))
print("π is:", math.pi)
print("The sin of 90 degrees is:", math.sin(math.radians(90)))
In [ ]:
math.
To get help with a particular function, type math.sin?
In [ ]:
math.erf?
In [ ]:
s = "Hello!"
In [ ]:
s.join() # or press <shift>+<tab> inside the brackets
In [ ]:
from IPython.display import Image
Image('imgs/leonardo.jpg')
In [ ]:
# HTML
from IPython.display import HTML
HTML('<b>Hello world!</b>')
In [ ]:
# Artsy videos
from IPython.display import VimeoVideo
VimeoVideo("150594088")
In [ ]:
# LaTeX!
from IPython.display import Latex
Latex(r"""\begin{eqnarray}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\,
\frac{\partial\vec{\mathbf{E}}}{\partial t} & = & \frac{4\pi}{c}\vec{\mathbf{j}} \\
\nabla \cdot \vec{\mathbf{E}} & = & 4 \pi \rho \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\,
\frac{\partial\vec{\mathbf{B}}}{\partial t} & = & \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = & 0
\end{eqnarray}""")
You can teach your own classes how to display themselves! Read the Rich display help.
In [ ]:
class Apple:
def __init__(self, colour):
self.colour = colour
def _repr_html_(self):
if self.colour == 'green':
url = ("https://www.infusioneliquid.com/wp-content"
"/uploads/2013/12/Green-Apples.jpg")
elif self.colour == 'red':
url = ("http://boutonrougedesigns.com/wp-content"
"/uploads/red-apple.jpg")
else:
url = ("http://static1.squarespace.com/static"
"/51623c20e4b01df404d682ae/t/542d5d05e4b09d76c5f801d8"
"/1412259082640/Be+the+job+candidate+that+stands+out+"
"from+the+rest+and+the+one+recruitment+consultants+choose+jpeg")
return "<img src=%s />"%url
In [ ]:
Apple("red")
In [ ]:
# Matplotlib
%config InlineBackend.figure_format='retina'
# gives you interactive plots
%matplotlib notebook
# rendered inline plots
#%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (6, 6)
plt.rcParams["figure.max_open_warning"] = -1
In [ ]:
# Taken from https://github.com/fperez/talk-1504-boulder/blob/master/QuickTour.ipynb
from scipy import special
import numpy as np
def plot_bessel(xmax=20, nmin=0, nmax=10, nstep=3):
x = np.linspace(0, xmax, 200)
f, ax = plt.subplots()
for n in range(nmin, nmax+1, nstep):
plt.plot(x, special.jn(n, x), label=r'$J_{%i(x)}$' % n)
plt.grid()
plt.legend()
plt.title('Bessel Functions')
plot_bessel()
In [ ]:
from IPython.html.widgets import interact
interact(plot_bessel, xmax=(10,100.), nmin=(0, 10),
nmax=(10, 30), nstep=(1,5));
In [ ]: