#!/usr/bin/env python # coding: utf-8 # In[33]: from IPython.display import Latex Latex(r"$\sqrt{x^2+y^2}$") # In[2]: from IPython.external.mathjax import install_mathjax install_mathjax() # In[14]: get_ipython().run_line_magic('reload_ext', 'sympyprinting') #from sympy import * #import sympy from sympy import init_printing init_printing() x, y = symbols("x,y") sqrt(x**2+y**2) from IPython.display import Image Image(filename="python.png") # In[16]: import cv2 import numpy as np from IPython.display import Image img = np.random.randint(0,255,(250,250,3)) cv2.blur(img, (11,11), img) r, dat = cv2.imencode(".png",img) Image(dat.tostring()) # In[19]: from IPython.display import Javascript Javascript("alert('JavaScript call, ok!客户端调用')") # In[25]: get_ipython().run_line_magic('timeit', '1 + 1') get_ipython().run_line_magic('timeit', '1.0 + 1.0') get_ipython().run_line_magic('timeit', '"1" + "1"') #10000000 loops, best of 3: 52 ns per loop #10000000 loops, best of 3: 53.4 ns per loop #10000000 loops, best of 3: 50.9 ns per loop #%%timeit s = 0 for i in range(100): s += i #100000 loops, best of 3: 11 us per loop # In[26]: get_ipython().run_line_magic('pylab', 'inline') plot(random.randn(100)); %load http://matplotlib.org/mpl_examples/pylab_examples/histogram_demo.py #!/usr/bin/env python import numpy as np import matplotlib.mlab as mlab import matplotlib.pyplot as plt mu, sigma = 100, 15 x = mu + sigma*np.random.randn(10000) # the histogram of the data n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green', alpha=0.75) # add a 'best fit' line y = mlab.normpdf( bins, mu, sigma) l = plt.plot(bins, y, 'r--', linewidth=1) plt.xlabel('Smarts') plt.ylabel('Probability') plt.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$') plt.axis([40, 160, 0, 0.03]) plt.grid(True) plt.show() # In[29]: get_ipython().run_cell_magic('prun', '', 'for i in range(100):\n linalg.det(random.rand(10,10))\n') # In[ ]: