Skip to content

Instantly share code, notes, and snippets.

@hokaccha
Created January 17, 2016 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hokaccha/cd09eb2564fc8e324fa6 to your computer and use it in GitHub Desktop.
Save hokaccha/cd09eb2564fc8e324fa6 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`%timeit`は実行時間を出力するマジックコマンド"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100000 loops, best of 3: 6.66 µs per loop\n"
]
}
],
"source": [
"%timeit range(1000)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"マジックコマンドの結果を受け取って利用できるものもある。`%sx`はシェルコマンドを実行して結果を返す。"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'I am hokamura'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"user = %sx whoami\n",
"\"I am %s\" % user[0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`%%`で始まるマジックコマンドは複数行を入力できる。`%%svg`はsvgを出力する。"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"120\" width=\"120\">\n",
" <circle cx=\"60\" cy=\"60\" fill=\"red\" r=\"50\"/>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%svg\n",
"<svg width=\"120\" height=\"120\">\n",
" <circle cx=\"60\" cy=\"60\" r=\"50\" fill=\"red\" />\n",
"</svg>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment