Skip to content

Instantly share code, notes, and snippets.

@tirinox
Created June 15, 2019 09:20
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 tirinox/87e551b00d81a072ab40a55405ae5480 to your computer and use it in GitHub Desktop.
Save tirinox/87e551b00d81a072ab40a55405ae5480 to your computer and use it in GitHub Desktop.
Demo of Jupyter's magic functions
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# нажми здесь shift+enter, чтобы увидеть список магий\n",
"%lsmagic"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# подробная документация по магиям\n",
"%magic"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# построение графиков\n",
"%matplotlib inline\n",
"from matplotlib import pyplot as plt\n",
"import numpy as np\n",
"x = np.linspace(0, 10, 100)\n",
"y = np.sin(x)\n",
"plt.plot(x, y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# нажми здесь shift+enter - будет документация по np.sin\n",
"np.sin?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def test():\n",
" return sum(range(1000))\n",
"%timeit test()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%timeit x = 10\n",
"x += 20\n",
"x /= 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# вывести переменные окрыжужения\n",
"%env"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# установить переменную окружения\n",
"%env TEST=10"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env TEST"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# если тут нажать shift+enter, то в ячейку будет загружен код из этого файла:\n",
"%load http://matplotlib.org/mpl_examples/pylab_examples/contour_demo.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# меняем текущую директорию\n",
"%cd /bin"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# вывести содержимое текущего калотого\n",
"!ls"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# установить новые библиотеки Python\n",
"!pip install click"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['tensorflow 1.12.0 ']\n"
]
}
],
"source": [
"# резульат выполнения системной команды можно получить в перемунную и использовать далее\n",
"output = !pip list | grep tensorflow\n",
"print(output)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment