2012/10/30

This is just a test of nbconvert.py

In [1]:
%pylab inline
x = linspace(0, 2*pi)
Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.
In [2]:
plot(x, sin(x), label=r'$\sin(x)$')
plot(x, cos(x), 'ro', label=r'$\cos(x)$')
title(r'Two familiar function')
Out [2]:
<matplotlib.text.Text at 0x105507cd0>
In [3]:
%load_ext sympyprinting
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/plugins/manager.py:418: UserWarning: Module dateutil was already imported from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dateutil/__init__.pyc, but /Users/yaboo/src/matplotlib/lib is being added to sys.path
  import pkg_resources
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/plugins/manager.py:418: UserWarning: Module six was already imported from /Users/yaboo/src/matplotlib/lib/six.pyc, but /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages is being added to sys.path
  import pkg_resources
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/extensions/sympyprinting.py:119: UserWarning: The sympyprinting extension in IPython is deprecated, use sympy.interactive.ipythonprinting
  warnings.warn("The sympyprinting extension in IPython is deprecated, "
In [4]:
import sympy as sym
from sympy import *
x, y, z = sym.symbols("x y z")
In [5]:
Rational(3,2)*pi + exp(I*x)/(x**2 + y)
Out [5]:
$$\frac{3}{2} \pi + \frac{e^{\mathbf{\imath} x}}{x^{2} + y}$$
In [6]:
eq = ((x+y)**2 * (x+1))
eq
Out [6]:
$$\left(x + 1\right) \left(x + y\right)^{2}$$
In [7]:
expand(eq)
Out [7]:
$$x^{3} + 2 x^{2} y + x^{2} + x y^{2} + 2 x y + y^{2}$$
In [8]:
diff(cos(x**2)**2 / (1 + x), x)
Out [8]:
$$- 4 \frac{x \sin{\left (x^{2} \right )} \cos{\left (x^{2} \right )}}{x + 1} - \frac{\cos^{2}{\left (x^{2} \right )}}{\left(x + 1\right)^{2}}$$

You can italicize, boldface

  • build
  • list
  • and embed code meant for illustration instead of execution in Python:

    def f(x):
        """a docstring"""
        return x**2
    

    or other languages:

    In [9]:
    from IPython.display import Image
    Image(filename=u'/Users/yaboo/Downloads/hoge.jpeg')
    
    Out [9]:
    In [10]:
    from IPython.display import YouTubeVideo
    YouTubeVideo('iwVvqwLDsJo')
    
    Out [10]:
    In [11]:
    %%ruby
    puts "Hello from Ruby #{RUBY_VERSION}"
    
    Hello from Ruby 1.8.7
    
    In [12]:
    %%bash
    echo "hello from $BASH"
    
    hello from /bin/bash
    
    In [13]:
    %load_ext rmagic
    X = np.array([0,1,2,3,4])
    Y = np.array([3,5,4,6,7])
    
    In [14]:
    %%R -i X,Y -o XYcoef
    XYlm = lm(Y~X)
    XYcoef = coef(XYlm)
    print(summary(XYlm))
    par(mfrow=c(2,2))
    plot(XYlm)
    
    Call:
    lm(formula = Y ~ X)
    
    Residuals:
       1    2    3    4    5 
    -0.2  0.9 -1.0  0.1  0.2 
    
    Coefficients:
                Estimate Std. Error t value Pr(>|t|)  
    (Intercept)   3.2000     0.6164   5.191   0.0139 *
    X             0.9000     0.2517   3.576   0.0374 *
    ---
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
    
    Residual standard error: 0.7958 on 3 degrees of freedom
    Multiple R-squared:  0.81, Adjusted R-squared: 0.7467 
    F-statistic: 12.79 on 1 and 3 DF,  p-value: 0.03739 
    
    
    In [42]:
    XYcoef
    
    Out [42]:
    [ 3.2  0.9]
    In [16]:
    load_ext cythonmagic
    
    In [17]:
    %%cython -lm
    from libc.math cimport sin
    print 'sin(1)=', sin(1)
    
    sin(1)= 0.841470984808
    

    No comments:

    Post a Comment

    100