Cell magic

Shell


In [1]:
!ls


ez_egy_minta_notebook.ipynb  interaktiv.ipynb	     markdown.ipynb
ez_egy_minta_notebook.zip    KRFT prezentáció.ipynb  octave.ipynb
indulagorogaludni.wav	     magic.ipynb	     webGL.ipynb

In [2]:
!ps x|grep python


 2302 ?        Sl     0:00 /usr/bin/python /usr/bin/blueman-applet
 2313 ?        Sl     0:10 /usr/bin/python3 /usr/bin/indicator-cpufreq
 2324 ?        Sl     0:03 /usr/bin/python /usr/share/system-config-printer/appl
 4617 ?        Sl     0:13 /usr/bin/python3 /usr/local/bin/jupyter-notebook --no
11388 ?        Sl     0:02 /usr/bin/python3 -m IPython.kernel -f /run/user/1000/
12209 ?        Sl     0:00 /usr/bin/python2.7 -m IPython.kernel -f /run/user/100
12259 ?        Sl     0:03 /usr/bin/python3 -m IPython.kernel -f /run/user/1000/
12462 ?        Sl     0:05 /usr/bin/python3 -m IPython.kernel -f /run/user/1000/
12507 ?        Sl     0:04 /usr/bin/python3 -m IPython.kernel -f /run/user/1000/
12890 ?        Sl     0:00 /usr/bin/python2.7 -m IPython.kernel -f /run/user/100
12913 pts/11   Ss+    0:00 /bin/sh -c ps x|grep python
12915 pts/11   S+     0:00 grep python

Fortran

A notebookba definiált fortran függvényeket a fortran_magic csomag segítségével tudjuk használni


In [3]:
%load_ext fortranmagic


/usr/local/lib/python2.7/dist-packages/IPython/utils/path.py:264: UserWarning: get_ipython_cache_dir has moved to the IPython.paths module
  warn("get_ipython_cache_dir has moved to the IPython.paths module")

In [4]:
%%fortran

subroutine f1(x, y, z)
    real, intent(in) :: x,y
    real, intent(out) :: z

    z = sin(x+y)

end subroutine f1

In [5]:
f1(3,4)


Out[5]:
0.6569865942001343

In [6]:
?f1

Octave

Octave kódot ipython-ból az oct2py csomag segítségével tudunk hívni.


In [7]:
%load_ext oct2py.ipython

In [8]:
%%octave
A=rand(10)


A =

 Columns 1 through 8:

  0.22425  0.24625  0.53771  0.44654  0.88576  0.42373  0.68136  0.51061
  0.70274  0.77759  0.63257  0.07283  0.40442  0.56725  0.16471  0.44224
  0.80263  0.05886  0.29032  0.68240  0.95559  0.23567  0.49142  0.86392
  0.15322  0.95112  0.33711  0.80755  0.93595  0.99139  0.95011  0.98641
  0.59346  0.39607  0.25361  0.53897  0.12727  0.91772  0.02262  0.93181
  0.54050  0.58792  0.89117  0.67274  0.90958  0.70609  0.20258  0.36015
  0.17277  0.70727  0.13866  0.57210  0.58139  0.94077  0.66275  0.12796
  0.59171  0.15255  0.19126  0.47101  0.53072  0.90097  0.82488  0.84875
  0.21817  0.19197  0.81380  0.45403  0.05483  0.93287  0.84168  0.82650
  0.26912  0.94119  0.47862  0.95004  0.72847  0.68283  0.08183  0.30373

 Columns 9 and 10:

  0.55322  0.41415
  0.93402  0.60311
  0.94578  0.07814
  0.44409  0.55035
  0.50859  0.40619
  0.24150  0.87458
  0.41587  0.48706
  0.71345  0.04251
  0.59883  0.59856
  0.20986  0.46976

In [9]:
A


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-9-bf072e911907> in <module>()
----> 1 A

NameError: name 'A' is not defined

In [10]:
x = %octave [1 2; 3 4];
x



Out[10]:
array([[ 1.,  2.],
       [ 3.,  4.]])

In [9]:
%%octave -f svg
p = [12 -2.5 -8 -0.1 8];
x = 0:0.01:1;

polyout(p, 'x')
plot(x, polyval(p, x));


12*x^4 - 2.5*x^3 - 8*x^2 - 0.1*x^1 + 8
Gnuplot Produced by GNUPLOT 4.6 patchlevel 4 6 6.5 7 7.5 8 8.5 9 9.5 0 0.2 0.4 0.6 0.8 1 gnuplot_plot_1a

In [ ]: