Поиск по блогу

понедельник, 3 марта 2014 г.

IPython Notebook Basics (3) SciPy2013 Tutorial, Part 2 of 3

Здесь пример использования 'from IPython.nbformat import current' из текущего файла считываются содержание первых пяти ячеек в формате json, как распечатать содержание ячеек по индексу... Это начал о видеоролика IPython in Depth, SciPy2013 Tutorial, Part 2 of 3

Project directory

  • IPython Notebooks are just files (.ipynb) on your file system
  • The Notebook server is aware of Notebooks in a single directory, which we call the Notebook directory
  • If you cd to a Notebook directory and type:
    ipython notebook
you will see the Notebooks in that directory in the dashboard

Notebook files

Notebook files:
  • Are just that - files (.ipynb) on your file system
  • Contain JSON data
In [1]:
from IPython.nbformat import current
with open('00 - Notebook Basics.ipynb') as f:
    nb = current.read(f, 'json')
In [2]:
nb.worksheets[0].cells[0:5]
Out[2]:
[{u'cell_type': u'heading',
  u'level': 1,
  u'metadata': {},
  u'source': u'IPython Notebook Basics'},
 {u'cell_type': u'heading',
  u'level': 2,
  u'metadata': {},
  u'source': u'Project directory'},
 {u'cell_type': u'markdown',
  u'metadata': {},
  u'source': u'* IPython Notebooks are just files (`.ipynb`) on your file system\n* The Notebook server is aware of Notebooks in a single directory, which we call the **Notebook directory**\n* If you cd to a Notebook directory and type:\n\n        ipython notebook\n\n  you will see the Notebooks in that directory in the dashboard'},
 {u'cell_type': u'heading',
  u'level': 2,
  u'metadata': {},
  u'source': u'Notebook files'},
 {u'cell_type': u'markdown',
  u'metadata': {},
  u'source': u'Notebook files:\n\n* Are just that - files (`.ipynb`) on your file system\n* Contain JSON data'}]
  • Embed code, Markdown text, LaTeX equations, images
  • Are version control friendly: post your Notebooks on GitHub
  • Can be viewed online by anyone at http://nbviewer.ipython.org
IPython Notebooks can also be exported to .py files (see "File:Download As" menu item). You can tell the Notebook server to always save these .py files alongside the .ipynb files by starting the Notebook as:
ipython notebook --script
You can import Notebooks from the main Dashboard or simply by copying a Notebook into the Notebook directory.

Exercise

Find a Notebook on http://nbviewer.ipython.org and Download it. Then import it into your running Notebook server using the Dashboard.

Overview of the UI

  • Dashboard
  • Notebook area and cells
  • Menu
  • Toolbar

Cell types

  • Code
  • Markdown
  • Raw text
  • Heading

Exercise

Create a new Notebook that has at least one of each cell type. Practice the following cell operations:
  • Moving up/down
  • Cut/Copy/Paste
  • Merge/Split

Keyboard shortcuts

  • Shift-Enter to run a cell
  • Ctrl-Enter to run a cell in place
  • All other keyboard shortcuts have the form: Ctrl-m ?
  • Show all keyboard shortcuts using Ctrl-m h

Exercise

Go back to that last Notebook and repeat some of those cell operations using keyboard shortcuts:
  • Inserting cells above/below
  • Delete cell
  • Move cell up/down
  • Cut/copy/paste cell
  • Changing cell types


Посты чуть ниже также могут вас заинтересовать

Комментариев нет:

Отправить комментарий