Created
April 17, 2022 10:36
-
-
Save iamirmasoud/f9287458be73d4903131e754ce423821 to your computer and use it in GitHub Desktop.
Jupyter Magic Commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "id": "62518d1a", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "application/json": { | |
| "cell": { | |
| "!": "OSMagics", | |
| "HTML": "Other", | |
| "SVG": "Other", | |
| "bash": "Other", | |
| "capture": "ExecutionMagics", | |
| "debug": "ExecutionMagics", | |
| "file": "Other", | |
| "html": "DisplayMagics", | |
| "javascript": "DisplayMagics", | |
| "js": "DisplayMagics", | |
| "latex": "DisplayMagics", | |
| "markdown": "DisplayMagics", | |
| "perl": "Other", | |
| "prun": "ExecutionMagics", | |
| "pypy": "Other", | |
| "python": "Other", | |
| "python2": "Other", | |
| "python3": "Other", | |
| "ruby": "Other", | |
| "script": "ScriptMagics", | |
| "sh": "Other", | |
| "svg": "DisplayMagics", | |
| "sx": "OSMagics", | |
| "system": "OSMagics", | |
| "time": "ExecutionMagics", | |
| "timeit": "ExecutionMagics", | |
| "writefile": "OSMagics" | |
| }, | |
| "line": { | |
| "alias": "OSMagics", | |
| "alias_magic": "BasicMagics", | |
| "autoawait": "AsyncMagics", | |
| "autocall": "AutoMagics", | |
| "automagic": "AutoMagics", | |
| "autosave": "KernelMagics", | |
| "bookmark": "OSMagics", | |
| "cat": "Other", | |
| "cd": "OSMagics", | |
| "clear": "KernelMagics", | |
| "colors": "BasicMagics", | |
| "conda": "PackagingMagics", | |
| "config": "ConfigMagics", | |
| "connect_info": "KernelMagics", | |
| "cp": "Other", | |
| "debug": "ExecutionMagics", | |
| "dhist": "OSMagics", | |
| "dirs": "OSMagics", | |
| "doctest_mode": "BasicMagics", | |
| "ed": "Other", | |
| "edit": "KernelMagics", | |
| "env": "OSMagics", | |
| "gui": "BasicMagics", | |
| "hist": "Other", | |
| "history": "HistoryMagics", | |
| "killbgscripts": "ScriptMagics", | |
| "ldir": "Other", | |
| "less": "KernelMagics", | |
| "lf": "Other", | |
| "lk": "Other", | |
| "ll": "Other", | |
| "load": "CodeMagics", | |
| "load_ext": "ExtensionMagics", | |
| "loadpy": "CodeMagics", | |
| "logoff": "LoggingMagics", | |
| "logon": "LoggingMagics", | |
| "logstart": "LoggingMagics", | |
| "logstate": "LoggingMagics", | |
| "logstop": "LoggingMagics", | |
| "ls": "Other", | |
| "lsmagic": "BasicMagics", | |
| "lx": "Other", | |
| "macro": "ExecutionMagics", | |
| "magic": "BasicMagics", | |
| "man": "KernelMagics", | |
| "matplotlib": "PylabMagics", | |
| "mkdir": "Other", | |
| "more": "KernelMagics", | |
| "mv": "Other", | |
| "notebook": "BasicMagics", | |
| "page": "BasicMagics", | |
| "pastebin": "CodeMagics", | |
| "pdb": "ExecutionMagics", | |
| "pdef": "NamespaceMagics", | |
| "pdoc": "NamespaceMagics", | |
| "pfile": "NamespaceMagics", | |
| "pinfo": "NamespaceMagics", | |
| "pinfo2": "NamespaceMagics", | |
| "pip": "PackagingMagics", | |
| "popd": "OSMagics", | |
| "pprint": "BasicMagics", | |
| "precision": "BasicMagics", | |
| "prun": "ExecutionMagics", | |
| "psearch": "NamespaceMagics", | |
| "psource": "NamespaceMagics", | |
| "pushd": "OSMagics", | |
| "pwd": "OSMagics", | |
| "pycat": "OSMagics", | |
| "pylab": "PylabMagics", | |
| "qtconsole": "KernelMagics", | |
| "quickref": "BasicMagics", | |
| "recall": "HistoryMagics", | |
| "rehashx": "OSMagics", | |
| "reload_ext": "ExtensionMagics", | |
| "rep": "Other", | |
| "rerun": "HistoryMagics", | |
| "reset": "NamespaceMagics", | |
| "reset_selective": "NamespaceMagics", | |
| "rm": "Other", | |
| "rmdir": "Other", | |
| "run": "ExecutionMagics", | |
| "save": "CodeMagics", | |
| "sc": "OSMagics", | |
| "set_env": "OSMagics", | |
| "store": "StoreMagics", | |
| "sx": "OSMagics", | |
| "system": "OSMagics", | |
| "tb": "ExecutionMagics", | |
| "time": "ExecutionMagics", | |
| "timeit": "ExecutionMagics", | |
| "unalias": "OSMagics", | |
| "unload_ext": "ExtensionMagics", | |
| "who": "NamespaceMagics", | |
| "who_ls": "NamespaceMagics", | |
| "whos": "NamespaceMagics", | |
| "xdel": "NamespaceMagics", | |
| "xmode": "BasicMagics" | |
| } | |
| }, | |
| "text/plain": [ | |
| "Available line magics:\n", | |
| "%alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cat %cd %clear %colors %conda %config %connect_info %cp %debug %dhist %dirs %doctest_mode %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %lf %lk %ll %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %lx %macro %magic %man %matplotlib %mkdir %more %mv %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %rep %rerun %reset %reset_selective %rm %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode\n", | |
| "\n", | |
| "Available cell magics:\n", | |
| "%%! %%HTML %%SVG %%bash %%capture %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile\n", | |
| "\n", | |
| "Automagic is ON, % prefix IS NOT needed for line magics." | |
| ] | |
| }, | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%lsmagic" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "id": "76eb9dbf", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%quickref" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "id": "a7408869", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Created `%currdir` as an alias for `%pwd`.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%alias_magic currdir pwd" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "id": "d93c3118", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'/home/masoud/Desktop'" | |
| ] | |
| }, | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%currdir" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "id": "5846714d", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def addition(a,b):\n", | |
| " return a+b" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "id": "94847e14", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Automatic calling is: Smart\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%autocall" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "id": "4224f721", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "------> addition(5, 5)\n", | |
| "------> addition(5, 5)\n" | |
| ] | |
| }, | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "10" | |
| ] | |
| }, | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "addition 5, 5" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 8, | |
| "id": "2ed7c66d", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Automatic calling is: Off\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%autocall" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 9, | |
| "id": "0402db1d", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "ename": "SyntaxError", | |
| "evalue": "invalid syntax (645643924.py, line 1)", | |
| "output_type": "error", | |
| "traceback": [ | |
| "\u001b[0;36m Input \u001b[0;32mIn [9]\u001b[0;36m\u001b[0m\n\u001b[0;31m addition 5, 5\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "addition 5, 5" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 10, | |
| "id": "95a91696", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "\n", | |
| "Automagic is OFF, % prefix IS needed for line magics.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%automagic" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 12, | |
| "id": "6d5953fb", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "ename": "NameError", | |
| "evalue": "name 'pwd' is not defined", | |
| "output_type": "error", | |
| "traceback": [ | |
| "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
| "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", | |
| "Input \u001b[0;32mIn [12]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mpwd\u001b[49m\n", | |
| "\u001b[0;31mNameError\u001b[0m: name 'pwd' is not defined" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "pwd" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 13, | |
| "id": "df2ef7a7", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "\n", | |
| "Automagic is ON, % prefix IS NOT needed for line magics.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%automagic" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 14, | |
| "id": "ab5ba8d0", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'/home/masoud/Desktop'" | |
| ] | |
| }, | |
| "execution_count": 14, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "pwd" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 16, | |
| "id": "7c294727", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "\n", | |
| "Automagic is OFF, % prefix IS needed for line magics.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%automagic" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 17, | |
| "id": "3c8e30d6", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'/home/masoud/Desktop'" | |
| ] | |
| }, | |
| "execution_count": 17, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%pwd" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 19, | |
| "id": "8139dbda", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['Hello World']" | |
| ] | |
| }, | |
| "execution_count": 19, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%system echo 'Hello World'" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 22, | |
| "id": "9bbfc4c0", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['-rw-rw-r-- 1 masoud masoud 11777 Apr 17 13:24 Jupyter Magic Commands.ipynb']" | |
| ] | |
| }, | |
| "execution_count": 22, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%system ls -lrt | grep Jupyter" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 23, | |
| "id": "d1b95abf", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['Hello World']" | |
| ] | |
| }, | |
| "execution_count": 23, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%sx echo 'Hello World'" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 24, | |
| "id": "7bb0b44e", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "CPU times: user 78.3 ms, sys: 15.9 ms, total: 94.2 ms\n", | |
| "Wall time: 92.6 ms\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%time out = [i*i for i in range(1000000)]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 25, | |
| "id": "ef765928", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "71.5 ms ± 2.78 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%timeit out = [i*i for i in range(1000000)]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 26, | |
| "id": "f30d9a81", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "68.2 ms ± 3.15 ms per loop (mean ± std. dev. of 5 runs, 5 loops each)\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%timeit -n 5 -r 5 out = [i*i for i in range(1000000)]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 28, | |
| "id": "3365c90a", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "e\t \n", | |
| "d\t \n", | |
| "b\t \n", | |
| "c\t out\t \n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "a = 100\n", | |
| "b = 5.5\n", | |
| "c = [11,12,13]\n", | |
| "d = {'key1':'val1', 'key2':'val2'}\n", | |
| "e = \"Hello World\"\n", | |
| "\n", | |
| "%who str\n", | |
| "%who dict\n", | |
| "%who float\n", | |
| "%who list" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 29, | |
| "id": "537d40bd", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def addition(a,b):\n", | |
| " return a + b\n", | |
| "\n", | |
| "def division(a,b):\n", | |
| " return a / b if b!=0 else 0" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 30, | |
| "id": "070f5360", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "addition\t division\t \n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "def addition(a,b):\n", | |
| " return a + b\n", | |
| "\n", | |
| "def division(a,b):\n", | |
| " return a / b if b!=0 else 0\n", | |
| "\n", | |
| "%who function" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 31, | |
| "id": "45025364", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "addition\t c\t division\t out\t \n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%who function list" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 33, | |
| "id": "6aba2821", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['addition', 'division']" | |
| ] | |
| }, | |
| "execution_count": 33, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%who_ls function" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 36, | |
| "id": "f8a61f05", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Variable Type Data/Info\n", | |
| "----------------------------\n", | |
| "e str Hello World\n", | |
| "Variable Type Data/Info\n", | |
| "----------------------------\n", | |
| "d dict n=2\n", | |
| "Variable Type Data/Info\n", | |
| "-----------------------------\n", | |
| "b float 5.5\n", | |
| "Variable Type Data/Info\n", | |
| "----------------------------\n", | |
| "c list n=3\n", | |
| "out list n=1000000\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%whos str\n", | |
| "%whos dict\n", | |
| "%whos float\n", | |
| "%whos list" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 37, | |
| "id": "377086db", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Variable Type Data/Info\n", | |
| "--------------------------------\n", | |
| "addition function <function addition at 0x7fc345799b40>\n", | |
| "division function <function division at 0x7fc345799990>\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%whos function" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 38, | |
| "id": "29af16f5", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[]" | |
| ] | |
| }, | |
| "execution_count": 38, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%system touch profiling_example.py" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "3e01a085", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# %load profiling_example.py\n", | |
| "from memory_profiler import profile\n", | |
| "\n", | |
| "@profile(precision=4)\n", | |
| "def main_func():\n", | |
| " import random\n", | |
| " arr1 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr2 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr3 = [arr1[i]+arr2[i] for i in range(100000)]\n", | |
| " tot = sum(arr3)\n", | |
| " print(tot)\n", | |
| "\n", | |
| "if __name__ == \"__main__\":\n", | |
| " main_func()\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "bdb3536d", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# %load -r 5-10 profiling_example.py\n", | |
| "import random\n", | |
| "arr1 = [random.randint(1,10) for i in range(100000)]\n", | |
| "arr2 = [random.randint(1,10) for i in range(100000)]\n", | |
| "arr3 = [arr1[i]+arr2[i] for i in range(100000)]\n", | |
| "tot = sum(arr3)\n", | |
| "print(tot)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "dd6d512d", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# %load -s main_func profiling_example.py\n", | |
| "def main_func():\n", | |
| " import random\n", | |
| " arr1 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr2 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr3 = [arr1[i]+arr2[i] for i in range(100000)]\n", | |
| " tot = sum(arr3)\n", | |
| " print(tot)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 45, | |
| "id": "be595aa7", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Collecting snakeviz\n", | |
| " Downloading snakeviz-2.1.1-py2.py3-none-any.whl (282 kB)\n", | |
| "\u001b[K |████████████████████████████████| 282 kB 153 kB/s eta 0:00:01\n", | |
| "\u001b[?25hCollecting line_profiler\n", | |
| " Downloading line_profiler-3.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (70 kB)\n", | |
| "\u001b[K |████████████████████████████████| 70 kB 396 kB/s eta 0:00:01\n", | |
| "\u001b[?25hCollecting memory_profiler\n", | |
| " Downloading memory_profiler-0.60.0.tar.gz (38 kB)\n", | |
| "Requirement already satisfied: tornado>=2.0 in /home/masoud/anaconda3/envs/music_env/lib/python3.10/site-packages (from snakeviz) (6.1)\n", | |
| "Requirement already satisfied: psutil in /home/masoud/anaconda3/envs/music_env/lib/python3.10/site-packages (from memory_profiler) (5.9.0)\n", | |
| "Building wheels for collected packages: memory-profiler\n", | |
| " Building wheel for memory-profiler (setup.py) ... \u001b[?25ldone\n", | |
| "\u001b[?25h Created wheel for memory-profiler: filename=memory_profiler-0.60.0-py3-none-any.whl size=31282 sha256=8bcd2d74a754158eddfcc0ee7d0358ac22ff14f293100e0885342d1c339a40e0\n", | |
| " Stored in directory: /home/masoud/.cache/pip/wheels/1e/2f/ec/05ba593810ab1a8f607baaec73f43a9238627f12e7bbb0d1a7\n", | |
| "Successfully built memory-profiler\n", | |
| "Installing collected packages: snakeviz, memory-profiler, line-profiler\n", | |
| "Successfully installed line-profiler-3.5.1 memory-profiler-0.60.0 snakeviz-2.1.1\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "!pip install snakeviz line_profiler memory_profiler" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 46, | |
| "id": "398211b3", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%load_ext snakeviz" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 47, | |
| "id": "2ad9f0de", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def main_func():\n", | |
| " import random\n", | |
| " arr1 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr2 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr3 = [arr1[i]+arr2[i] for i in range(100000)]\n", | |
| " tot = sum(arr3)\n", | |
| " print(tot)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 49, | |
| "id": "038a44e1", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "1098735\n", | |
| " \n", | |
| "*** Profile stats marshalled to file '/tmp/tmpippki01l'.\n", | |
| "Embedding SnakeViz in this document...\n" | |
| ] | |
| }, | |
| { | |
| "data": { | |
| "text/html": [ | |
| "\n", | |
| "<iframe id='snakeviz-acd0551a-be2f-11ec-8a00-e956bae7604a' frameborder=0 seamless width='100%' height='1000'></iframe>\n", | |
| "<script>document.getElementById(\"snakeviz-acd0551a-be2f-11ec-8a00-e956bae7604a\").setAttribute(\"src\", \"http://\" + document.location.hostname + \":8080/snakeviz/%2Ftmp%2Ftmpippki01l\")</script>\n" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.HTML object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "%snakeviz main_func()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 51, | |
| "id": "5e487bd4", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "The snakeviz extension doesn't define how to unload it.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%unload_ext snakeviz" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 52, | |
| "id": "bccfea9d", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%reload_ext snakeviz" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 55, | |
| "id": "4cd4f9ac", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'ubuntu'" | |
| ] | |
| }, | |
| "execution_count": 55, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%env DESKTOP_SESSION" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 56, | |
| "id": "0cb76f49", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'/home/masoud'" | |
| ] | |
| }, | |
| "execution_count": 56, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%env HOME" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 57, | |
| "id": "a4e5bcfd", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "env: TESTIT=test_value\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%env TESTIT=test_value" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 58, | |
| "id": "4fb02bb1", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'test_value'" | |
| ] | |
| }, | |
| "execution_count": 58, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%env TESTIT" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 60, | |
| "id": "c1753d98", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "# conda environments:\n", | |
| "#\n", | |
| "base /home/masoud/anaconda3\n", | |
| "ThinkBayes2 /home/masoud/anaconda3/envs/ThinkBayes2\n", | |
| "backtest_env /home/masoud/anaconda3/envs/backtest_env\n", | |
| "drnd_env /home/masoud/anaconda3/envs/drnd_env\n", | |
| "fidibo /home/masoud/anaconda3/envs/fidibo\n", | |
| "gdrl_env /home/masoud/anaconda3/envs/gdrl_env\n", | |
| "music_env * /home/masoud/anaconda3/envs/music_env\n", | |
| "separator_env /home/masoud/anaconda3/envs/separator_env\n", | |
| "vocal_env /home/masoud/anaconda3/envs/vocal_env\n", | |
| "\n", | |
| "\n", | |
| "Note: you may need to restart the kernel to use updated packages.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%conda env list" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 61, | |
| "id": "7606a360", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Requirement already satisfied: sklearn in /home/masoud/anaconda3/envs/music_env/lib/python3.10/site-packages (0.0)\n", | |
| "Requirement already satisfied: scikit-learn in /home/masoud/anaconda3/envs/music_env/lib/python3.10/site-packages (from sklearn) (1.0.2)\n", | |
| "Requirement already satisfied: numpy>=1.14.6 in /home/masoud/anaconda3/envs/music_env/lib/python3.10/site-packages (from scikit-learn->sklearn) (1.21.5)\n", | |
| "Requirement already satisfied: scipy>=1.1.0 in /home/masoud/anaconda3/envs/music_env/lib/python3.10/site-packages (from scikit-learn->sklearn) (1.8.0)\n", | |
| "Requirement already satisfied: threadpoolctl>=2.0.0 in /home/masoud/anaconda3/envs/music_env/lib/python3.10/site-packages (from scikit-learn->sklearn) (3.1.0)\n", | |
| "Requirement already satisfied: joblib>=0.11 in /home/masoud/anaconda3/envs/music_env/lib/python3.10/site-packages (from scikit-learn->sklearn) (1.1.0)\n", | |
| "Note: you may need to restart the kernel to use updated packages.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%pip install sklearn" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 62, | |
| "id": "02c7c258", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Directory history (kept in _dh)\n", | |
| "0: /home/masoud/Desktop\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%dhist" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 64, | |
| "id": "74129779", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| " 6: %autocall\n", | |
| " 7: addition 5, 5\n", | |
| " 8: %autocall\n", | |
| " 9: addition 5, 5\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%history -n 6-9" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 65, | |
| "id": "93e5e7b5", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| " 6: >>> %autocall\n", | |
| " 7: >>> addition 5, 5\n", | |
| " 8: >>> %autocall\n", | |
| " 9: >>> addition 5, 5\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%history -n 6-9 -p" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 66, | |
| "id": "a10e534f", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%history 6-9 -p -f magic.out" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 71, | |
| "id": "955394fa", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Exception reporting mode: Plain\n", | |
| "Doctest mode is: ON\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%doctest_mode" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 72, | |
| "id": "0f060075", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "ename": "ZeroDivisionError", | |
| "evalue": "division by zero", | |
| "output_type": "error", | |
| "traceback": [ | |
| "Traceback \u001b[0;36m(most recent call last)\u001b[0m:\n", | |
| "\u001b[0;36m Input \u001b[0;32mIn [72]\u001b[0;36m in \u001b[0;35m<cell line: 2>\u001b[0;36m\u001b[0m\n\u001b[0;31m a/0\u001b[0m\n", | |
| "\u001b[0;31mZeroDivisionError\u001b[0m\u001b[0;31m:\u001b[0m division by zero\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "a=10\n", | |
| "a/0" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 73, | |
| "id": "27b0f9a0", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Exception reporting mode: Context\n", | |
| "Doctest mode is: OFF\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%doctest_mode" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 74, | |
| "id": "2e00bd21", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| " " | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "import random\n", | |
| "%prun arr1 = [random.randint(1,10) for i in range(100000)]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 75, | |
| "id": "d0b07a3f", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| " \n", | |
| "*** Profile printout saved to text file 'prof_res.out'.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%prun -l 10 -s tottime -T prof_res.out arr1 = [random.randint(1,10) for i in range(100000)]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 76, | |
| "id": "6b865379", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| " 859711 function calls in 0.248 seconds\r\n", | |
| "\r\n", | |
| " Ordered by: internal time\r\n", | |
| "\r\n", | |
| " ncalls tottime percall cumtime percall filename:lineno(function)\r\n", | |
| " 100000 0.089 0.000 0.191 0.000 random.py:292(randrange)\r\n", | |
| " 100000 0.060 0.000 0.083 0.000 random.py:239(_randbelow_with_getrandbits)\r\n", | |
| " 100000 0.030 0.000 0.222 0.000 random.py:366(randint)\r\n", | |
| " 1 0.026 0.026 0.248 0.248 <string>:1(<listcomp>)\r\n", | |
| " 300000 0.020 0.000 0.020 0.000 {built-in method _operator.index}\r\n", | |
| " 159707 0.015 0.000 0.015 0.000 {method 'getrandbits' of '_random.Random' objects}\r\n", | |
| " 100000 0.008 0.000 0.008 0.000 {method 'bit_length' of 'int' objects}\r\n", | |
| " 1 0.000 0.000 0.248 0.248 {built-in method builtins.exec}\r\n", | |
| " 1 0.000 0.000 0.248 0.248 <string>:1(<module>)\r\n", | |
| " 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "!cat prof_res.out" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 77, | |
| "id": "ce6d98bc", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Available matplotlib backends: ['tk', 'gtk', 'gtk3', 'gtk4', 'wx', 'qt4', 'qt5', 'qt6', 'qt', 'osx', 'nbagg', 'notebook', 'agg', 'svg', 'pdf', 'ps', 'inline', 'ipympl', 'widget']\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%matplotlib --list" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 78, | |
| "id": "54a3e329", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Using matplotlib backend: <object object at 0x7fc33416c280>\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%matplotlib" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 81, | |
| "id": "02f2f4be", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import matplotlib.pyplot as plt\n", | |
| "\n", | |
| "plt.plot(range(10), range(10))\n", | |
| "plt.show()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 82, | |
| "id": "84863de9", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%matplotlib inline" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 83, | |
| "id": "ac615c9b", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAd1klEQVR4nO3dd2BV5eHG8e8LIUCAMMMIEBIIKyFBIGwnLhRREFu1bmqx/WmrtRXCUFFRcdRqrQvcVWuVhD1E6iguFBCywwgjYQZCBtnJfX9/QCsqygXuzbm59/n8RQbJ4yF5PDm557nGWouIiPiuBk4HEBGRn6eiFhHxcSpqEREfp6IWEfFxKmoRER8X5I0P2q5dOxsZGemNDy0i4pfWrVt3wFobdry3eaWoIyMjWbt2rTc+tIiIXzLG7Pipt+nSh4iIj1NRi4j4OBW1iIiPU1GLiPg4FbWIiI9TUYuI+DgVtYiIj1NRi4h4wDfbC3jx061e+dheueFFRCRQHK6s4fEVWbz55Q4i2oRw4/BuhAR7tlpV1CIip+iT7P1Mn5/G7qJybhkZyZ8v6u3xkgYVtYjISTtUWsVDSzNIXr+L6PbNmffbEQzq1tprn09FLSLiJmsty9P2ct/CNArLqvn9qGjuGBVN46CGXv28KmoRETfsL67g3oVpfJC+j7jOLXlz4lBiwkPr5HOrqEVEfoa1lvfX5TFrSQaVNS6mXtKHX58ZRVDDunvQnIpaROQn5BaUMTU5lc+2HGBIVBtmXxlH97DmdZ5DRS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d3/P1Y6NKHiIiPU1GLiPg4XyzqOU4H8CE6Ft+n4/F9Oh7f8etj4XPXqEVE5Pt88YxaRESOoaIWEfFxPlPUxpjRxphsY8wWY0yi03mcZIzpaoz52BiTaYxJN8bc6XQmpxljGhpjvjXGLHE6i9OMMa2MMfOMMVlHv0aGO53JScaYPx79PkkzxvzTGNPE6Uye5hNFfcwT6F4CxADXGmNinE3lqBrgT9bavsAw4PYAPx4AdwKZTofwEc8AK6y1fYD+BPBxMcZ0Bv4AJFhr+3FkivkaZ1N5nk8UNcc8ga61tgr47xPoBiRr7R5r7fqjfy7hyDdiZ2dTOccY0wUYA7zsdBanGWNCgbOBVwCstVXW2kJHQzkvCGhqjAkCQvDDZ6DylaI+3hPoBmwxHcsYEwkMANY4HMVJTwOTAZfDOXxBdyAfeO3opaCXjTHNnA7lFGvtLuBJYCewByiy1q50NpXn+UpRu/UEuoHGGNMcSALustYWO53HCcaYy4D91tp1TmfxEUHAQOAFa+0AoBQI2N/pGGNac+Sn7yggHGhmjLne2VSe5ytFrSfQ/QFjTCOOlPTb1tpkp/M4aCRwuTFmO0cuiY0yxrzlbCRH5QF51tr//oQ1jyPFHaguALZZa/OttdVAMjDC4Uwe5ytFrSfQPYYxxnDkGmSmtfYpp/M4yVo71VrbxVobyZGvi4+stX53xuQua+1eINcY0/voq84HMhyM5LSdwDBjTMjR75vz8cNfrrr1nInepifQ/ZGRwA1AqjFmw9HXTTv63JUivwfePnpSkwPc4nAex1hr1xhj5gHrOfJoqW/xw9vJdQu5iIiP85VLHyIi8hNU1CIiPk5FLSLi41TUIiI+TkUtIuLjVNQiIj5ORS0i4uP+H4dAYanAnZolAAAAAElFTkSuQmCC\n", | |
| "text/plain": [ | |
| "<Figure size 432x288 with 1 Axes>" | |
| ] | |
| }, | |
| "metadata": { | |
| "needs_background": "light" | |
| }, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "plt.plot(range(10), range(10))\n", | |
| "plt.show()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 84, | |
| "id": "606cfeb8", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| " \u001b[0mdivision\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
| " " | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%pdef division" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 85, | |
| "id": "e4df3c0c", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def division(a, b):\n", | |
| " '''\n", | |
| " This function divides first argument by second. \n", | |
| " It return 0 if second argument is 0 to avoid divide by zero error\n", | |
| " '''\n", | |
| " return a / b if b!=0 else 0" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 86, | |
| "id": "dff505cf", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%pdoc division" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 88, | |
| "id": "77374b9b", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'%.3f'" | |
| ] | |
| }, | |
| "execution_count": 88, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%precision 3" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 89, | |
| "id": "63f8265a", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "a = 1.23678" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 90, | |
| "id": "df8f7280", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "1.237" | |
| ] | |
| }, | |
| "execution_count": 90, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "a" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 91, | |
| "id": "4945b620", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "val1 = 10\n", | |
| "val2 = 20\n", | |
| "val3 = 50\n", | |
| "top_val = 10000" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 92, | |
| "id": "0d4dd98b", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%psearch val*" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 93, | |
| "id": "6bed45da", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%psearch *val*" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 94, | |
| "id": "fb3339c1", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%psource division" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 95, | |
| "id": "56e33ac1", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%pycat profiling_example.py" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 96, | |
| "id": "a7c9dcef", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Using matplotlib backend: TkAgg\n", | |
| "%pylab is deprecated, use %matplotlib inline and import the required libraries.\n", | |
| "Populating the interactive namespace from numpy and matplotlib\n" | |
| ] | |
| }, | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "/home/masoud/anaconda3/envs/music_env/lib/python3.10/site-packages/IPython/core/magics/pylab.py:162: UserWarning: pylab import has clobbered these variables: ['random', 'e']\n", | |
| "`%matplotlib` prevents importing * from pylab and numpy\n", | |
| " warn(\"pylab import has clobbered these variables: %s\" % clobbered +\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%pylab" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 97, | |
| "id": "4328252c", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "numpy.ndarray" | |
| ] | |
| }, | |
| "execution_count": 97, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "arr = array([1,2,3,4])\n", | |
| "type(arr)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 98, | |
| "id": "040c08df", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "[0 1 2 3 4 5 6 7 8 9]\n" | |
| ] | |
| }, | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "numpy.ndarray" | |
| ] | |
| }, | |
| "execution_count": 98, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "rng = arange(10)\n", | |
| "print(rng)\n", | |
| "type(rng)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 99, | |
| "id": "212a9c40", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[<matplotlib.lines.Line2D at 0x7fc3222b0820>]" | |
| ] | |
| }, | |
| "execution_count": 99, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "plot(range(10), range(10))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 100, | |
| "id": "2618b0fd", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%recall 4" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "14313f5c", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%currdir" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 101, | |
| "id": "7edf53fb", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%recall 1-4" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "ca8092b2", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%lsmagic\n", | |
| "%quickref\n", | |
| "%alias_magic currdir pwd\n", | |
| "%currdir" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 102, | |
| "id": "80b18827", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "=== Executing: ===\n", | |
| "%recall 1-4\n", | |
| "=== Output: ===\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%rerun" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "ddc0c93c", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%lsmagic\n", | |
| "%quickref\n", | |
| "%alias_magic currdir pwd\n", | |
| "%currdir" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 103, | |
| "id": "bebc2f32", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['a',\n", | |
| " 'addition',\n", | |
| " 'arr',\n", | |
| " 'arr1',\n", | |
| " 'autopep8',\n", | |
| " 'b',\n", | |
| " 'c',\n", | |
| " 'd',\n", | |
| " 'division',\n", | |
| " 'json',\n", | |
| " 'main_func',\n", | |
| " 'out',\n", | |
| " 'rng',\n", | |
| " 'top_val',\n", | |
| " 'val1',\n", | |
| " 'val2',\n", | |
| " 'val3']" | |
| ] | |
| }, | |
| "execution_count": 103, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%who_ls" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 104, | |
| "id": "e432d2a6", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Once deleted, variables cannot be recovered. Proceed (y/[n])? y\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%reset" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 105, | |
| "id": "8c5fb2e1", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "ename": "NameError", | |
| "evalue": "name 'val1' is not defined", | |
| "output_type": "error", | |
| "traceback": [ | |
| "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
| "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", | |
| "Input \u001b[0;32mIn [105]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mval1\u001b[49m\n", | |
| "\u001b[0;31mNameError\u001b[0m: name 'val1' is not defined" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "val1" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 109, | |
| "id": "12649582", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "val1 = 10\n", | |
| "val2 = 20\n", | |
| "val3 = 50\n", | |
| "top_val = 10000\n", | |
| "a = 10\n", | |
| "rng = range(10)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 110, | |
| "id": "6ef0b573", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['a', 'rng', 'top_val', 'val1', 'val2', 'val3']" | |
| ] | |
| }, | |
| "execution_count": 110, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%who_ls" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 111, | |
| "id": "7e6fb0c1", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "%reset_selective -f val" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 112, | |
| "id": "e0c6b511", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['a', 'rng']" | |
| ] | |
| }, | |
| "execution_count": 112, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%who_ls" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 113, | |
| "id": "37343227", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "1100192\n", | |
| "Filename: /home/masoud/Desktop/profiling_example.py\n", | |
| "\n", | |
| "Line # Mem usage Increment Occurrences Line Contents\n", | |
| "=============================================================\n", | |
| " 3 175.5625 MiB 175.5625 MiB 1 @profile(precision=4)\n", | |
| " 4 def main_func():\n", | |
| " 5 175.5625 MiB 0.0000 MiB 1 import random\n", | |
| " 6 176.2617 MiB 0.6992 MiB 100003 arr1 = [random.randint(1,10) for i in range(100000)]\n", | |
| " 7 177.0352 MiB 0.7734 MiB 100003 arr2 = [random.randint(1,10) for i in range(100000)]\n", | |
| " 8 177.8086 MiB 0.7734 MiB 100003 arr3 = [arr1[i]+arr2[i] for i in range(100000)]\n", | |
| " 9 177.8086 MiB 0.0000 MiB 1 tot = sum(arr3)\n", | |
| " 10 177.8086 MiB 0.0000 MiB 1 print(tot)\n", | |
| "\n", | |
| "\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%run profiling_example.py" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 114, | |
| "id": "ca0bcb77", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "-rw-rw-r-- 1 masoud masoud 52575 Apr 17 14:54 Jupyter Magic Commands.ipynb\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%%bash\n", | |
| "\n", | |
| "ls -lrt | grep \"Jupyter\"" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 116, | |
| "id": "7219d8e9", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "-rw-rw-r-- 1 masoud masoud 52575 Apr 17 14:54 Jupyter Magic Commands.ipynb\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%%script bash\n", | |
| "ls -lrt | grep \"Jupyter\"" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 117, | |
| "id": "9823f4f6", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "-rw-rw-r-- 1 masoud masoud 52575 Apr 17 14:54 Jupyter Magic Commands.ipynb\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%%sh\n", | |
| "ls -lrt | grep \"Jupyter\"" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 118, | |
| "id": "297b386a", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<h1>Heading Big</h1>\n", | |
| "<h2>Heading Medium</h2>\n", | |
| "<h3>Heading Small</h3>\n", | |
| "# Comment\n" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.HTML object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "%%html\n", | |
| "<h1>Heading Big</h1>\n", | |
| "<h2>Heading Medium</h2>\n", | |
| "<h3>Heading Small</h3>\n", | |
| "# Comment" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 121, | |
| "id": "ad11a950", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "application/javascript": [ | |
| "// program to find the largest among three numbers\n", | |
| "// take input from the user\n", | |
| "const num1 = 12\n", | |
| "const num2 = 10\n", | |
| "const num3 = 35\n", | |
| "let largest;\n", | |
| "// check the condition\n", | |
| "if(num1 >= num2 && num1 >= num3) {\n", | |
| " largest = num1;\n", | |
| "}\n", | |
| "else if (num2 >= num1 && num2 >= num3) {\n", | |
| " largest = num2;\n", | |
| "}\n", | |
| "else {\n", | |
| " largest = num3;\n", | |
| "}\n", | |
| "// display the result\n", | |
| "element.innerHTML = '<h1>The Largest Number is : ' + largest + '</h1>'\n" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Javascript object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "%%javascript\n", | |
| "// program to find the largest among three numbers\n", | |
| "// take input from the user\n", | |
| "const num1 = 12\n", | |
| "const num2 = 10\n", | |
| "const num3 = 35\n", | |
| "let largest;\n", | |
| "// check the condition\n", | |
| "if(num1 >= num2 && num1 >= num3) {\n", | |
| " largest = num1;\n", | |
| "}\n", | |
| "else if (num2 >= num1 && num2 >= num3) {\n", | |
| " largest = num2;\n", | |
| "}\n", | |
| "else {\n", | |
| " largest = num3;\n", | |
| "}\n", | |
| "// display the result\n", | |
| "element.innerHTML = '<h1>The Largest Number is : ' + largest + '</h1>'" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 123, | |
| "id": "69992911", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Hello Bill\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%%perl\n", | |
| "#!/usr/bin/perl\n", | |
| "use strict;\n", | |
| "use warnings;\n", | |
| "print \"Hello Bill\\n\";" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 124, | |
| "id": "9a05117c", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "There are 50 Tigers and 45 Lions in the Zoo.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%%ruby\n", | |
| "tigers = 50\n", | |
| "lions = 45\n", | |
| "puts \"There are #{tigers} Tigers and #{lions} Lions in the Zoo.\"" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 125, | |
| "id": "a2c01fc6", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/latex": [ | |
| "\\begin{equation*}\n", | |
| " e^{\\pi i} + 1 = 0\n", | |
| "\\end{equation*}\n" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Latex object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "%%latex\n", | |
| "\\begin{equation*}\n", | |
| " e^{\\pi i} + 1 = 0\n", | |
| "\\end{equation*}" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 126, | |
| "id": "5401fe37", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/latex": [ | |
| "$\n", | |
| "idf(t) = {\\log_{} \\dfrac {n_d} {df(d,t)}} + 1\n", | |
| "$\n" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Latex object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "%%latex\n", | |
| "$\n", | |
| "idf(t) = {\\log_{} \\dfrac {n_d} {df(d,t)}} + 1\n", | |
| "$" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 127, | |
| "id": "d1a209db", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/markdown": [ | |
| "# H1 Heading\n", | |
| "# H2 Heading\n", | |
| "* List 1\n", | |
| "* List 2\n", | |
| "**Bold Text**\n" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Markdown object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "%%markdown\n", | |
| "# H1 Heading\n", | |
| "# H2 Heading\n", | |
| "* List 1\n", | |
| "* List 2\n", | |
| "**Bold Text**" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 128, | |
| "id": "7e02651b", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Overwriting profiling_example.py\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%%writefile profiling_example.py\n", | |
| "from memory_profiler import profile\n", | |
| "\n", | |
| "@profile(precision=4)\n", | |
| "def main_func():\n", | |
| " import random\n", | |
| " arr1 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr2 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr3 = [arr1[i]+arr2[i] for i in range(100000)]\n", | |
| " tot = sum(arr3)\n", | |
| " print(tot)\n", | |
| "\n", | |
| "if __name__ == \"__main__\":\n", | |
| " main_func()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 129, | |
| "id": "fbcefacf", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "from memory_profiler import profile\r\n", | |
| "\r\n", | |
| "@profile(precision=4)\r\n", | |
| "def main_func():\r\n", | |
| " import random\r\n", | |
| " arr1 = [random.randint(1,10) for i in range(100000)]\r\n", | |
| " arr2 = [random.randint(1,10) for i in range(100000)]\r\n", | |
| " arr3 = [arr1[i]+arr2[i] for i in range(100000)]\r\n", | |
| " tot = sum(arr3)\r\n", | |
| " print(tot)\r\n", | |
| "\r\n", | |
| "if __name__ == \"__main__\":\r\n", | |
| " main_func()\r\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "!cat profiling_example.py" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 130, | |
| "id": "cb3648eb", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "1102714\n", | |
| "CPU times: user 174 ms, sys: 2.04 ms, total: 176 ms\n", | |
| "Wall time: 174 ms\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%%time\n", | |
| "def main_func():\n", | |
| " import random\n", | |
| " arr1 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr2 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr3 = [arr1[i]+arr2[i] for i in range(100000)]\n", | |
| " tot = sum(arr3)\n", | |
| " print(tot)\n", | |
| "\n", | |
| "main_func()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 131, | |
| "id": "762df033", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def main_func():\n", | |
| " import random\n", | |
| " arr1 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr2 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr3 = [arr1[i]+arr2[i] for i in range(100000)]\n", | |
| " tot = sum(arr3)\n", | |
| "\n", | |
| "main_func()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 132, | |
| "id": "8c74a55d", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "150 ms ± 9.78 ms per loop (mean ± std. dev. of 5 runs, 5 loops each)\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%%timeit -n 5 -r 5\n", | |
| "def main_func():\n", | |
| " import random\n", | |
| " arr1 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr2 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr3 = [arr1[i]+arr2[i] for i in range(100000)]\n", | |
| " tot = sum(arr3)\n", | |
| "main_func()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 134, | |
| "id": "dabc4369", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "263 ms ± 2.25 ms per loop (mean ± std. dev. of 5 runs, 5 loops each)\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%%timeit -t -n 5 -r 5\n", | |
| "import random\n", | |
| "arr1 = [random.randint(1,10) for i in range(100000)]\n", | |
| "arr2 = [random.randint(1,10) for i in range(100000)]\n", | |
| "arr3 = [arr1[i]+arr2[i] for i in range(100000)]\n", | |
| "tot = sum(arr3)\n", | |
| "\n", | |
| "main_func()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 135, | |
| "id": "35212b4e", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "1100751\n", | |
| " " | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%%prun\n", | |
| "def main_func():\n", | |
| " import random\n", | |
| " arr1 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr2 = [random.randint(1,10) for i in range(100000)]\n", | |
| " arr3 = [arr1[i]+arr2[i] for i in range(100000)]\n", | |
| " tot = sum(arr3)\n", | |
| " print(tot)\n", | |
| "\n", | |
| "main_func()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "7c04e1dd", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python (music_env)", | |
| "language": "python", | |
| "name": "music_env" | |
| }, | |
| "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.10.4" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment