1088 lines
46 KiB
Plaintext
1088 lines
46 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "auburn-huntington",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Getting started with Python / Interactive Python with Jupyter Lab\n",
|
|
"\n",
|
|
"## Installing miniconda\n",
|
|
"\n",
|
|
"- https://docs.conda.io/en/latest/miniconda.html\n",
|
|
"- https://youtu.be/YqUb9XALnDE?t=209"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "labeled-unknown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Printing and Variable"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"id": "asian-catalog",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Hello World\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(\"Hello World\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"id": "robust-customs",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# comments are done like this"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"id": "chicken-broadcast",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"10\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"number = 10\n",
|
|
"string = \"This is a string\"\n",
|
|
"\n",
|
|
"print(number)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"id": "suburban-august",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"This is a string\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(string)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 18,
|
|
"id": "dramatic-brand",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"number: 10, and string: This is a string\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(f\"number: {number}, and string: {string}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"id": "female-spain",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"<class 'int'> and <class 'str'>\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(f\"{type(number)} and {type(string)}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "immediate-worst",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Functions"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 20,
|
|
"id": "favorite-damages",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8...\n",
|
|
"\n",
|
|
"def f(n: int) -> int:\n",
|
|
" \"\"\"\n",
|
|
" Fibonacci sequence\n",
|
|
" ---\n",
|
|
" params\n",
|
|
" n (int) number requested in sequence\n",
|
|
" \n",
|
|
" returns\n",
|
|
" interger in fibonacci sequence\n",
|
|
" \"\"\"\n",
|
|
" if n == 0:\n",
|
|
" return 0\n",
|
|
" if n == 1:\n",
|
|
" return 1\n",
|
|
" if n == 2:\n",
|
|
" return 1\n",
|
|
" if n >= 3:\n",
|
|
" return f(n-1) + f(n-2)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 21,
|
|
"id": "reliable-nudist",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"\u001b[0;31mSignature:\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0;31mDocstring:\u001b[0m\n",
|
|
"Fibonacci sequence\n",
|
|
"---\n",
|
|
"params\n",
|
|
"n (int) number requested in sequence\n",
|
|
"\n",
|
|
"returns\n",
|
|
"interger in fibonacci sequence\n",
|
|
"\u001b[0;31mFile:\u001b[0m ~/JupyterlabProjects/Saxon/<ipython-input-20-d0995f361bf4>\n",
|
|
"\u001b[0;31mType:\u001b[0m function\n"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"?f"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "leading-literacy",
|
|
"metadata": {},
|
|
"source": [
|
|
"### More data type - Lists"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 22,
|
|
"id": "alternate-fault",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"range(0, 10)"
|
|
]
|
|
},
|
|
"execution_count": 22,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"r = range(10)\n",
|
|
"r"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 24,
|
|
"id": "tutorial-buying",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
|
|
]
|
|
},
|
|
"execution_count": 24,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"lst = list(r)\n",
|
|
"lst"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 25,
|
|
"id": "south-czech",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0"
|
|
]
|
|
},
|
|
"execution_count": 25,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"lst[0]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 26,
|
|
"id": "administrative-class",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"[1, 2]"
|
|
]
|
|
},
|
|
"execution_count": 26,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"lst[1:3]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 31,
|
|
"id": "grateful-addiction",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"9"
|
|
]
|
|
},
|
|
"execution_count": 31,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"lst[-1]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 28,
|
|
"id": "brown-density",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]"
|
|
]
|
|
},
|
|
"execution_count": 28,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"lst[::-1]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "exciting-fundamental",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"3\n",
|
|
"4\n",
|
|
"0.5\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"def f1(x: int) -> int:\n",
|
|
" return x + 1\n",
|
|
"\n",
|
|
"def f2(x: int) -> int:\n",
|
|
" return x ** 2\n",
|
|
"\n",
|
|
"def f3(x: int) -> float:\n",
|
|
" return 1 / x\n",
|
|
"\n",
|
|
"funcs = [f1, f2, f3]\n",
|
|
"\n",
|
|
"for func in funcs:\n",
|
|
" print(func(2))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 29,
|
|
"id": "together-lancaster",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"0, 1, 1, 2, 3, 5, 8, 13, 21, 34, "
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"for i in lst:\n",
|
|
" output = f(i)\n",
|
|
" print(output, end=\", \")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 30,
|
|
"id": "governmental-karma",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]"
|
|
]
|
|
},
|
|
"execution_count": 30,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"output = []\n",
|
|
"for i in lst:\n",
|
|
" output.append(f(i))\n",
|
|
"output"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"id": "latter-plumbing",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]"
|
|
]
|
|
},
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"[f(i) for i in rng]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "offensive-documentation",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Importing libraries"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 32,
|
|
"id": "organizational-easter",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"288 ns ± 246 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"302 ns ± 252 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"304 ns ± 204 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"623 ns ± 288 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"957 ns ± 326 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"2.39 µs ± 880 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"2.28 µs ± 424 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"3.56 µs ± 411 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"5.62 µs ± 447 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"9.05 µs ± 598 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"14.4 µs ± 623 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"23.9 µs ± 2.03 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"36.9 µs ± 534 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"61.1 µs ± 3.57 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"96.1 µs ± 506 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"155 µs ± 677 ns per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"252 µs ± 5.16 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"485 µs ± 183 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"807 µs ± 125 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"1.45 ms ± 245 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"1.84 ms ± 152 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"3.27 ms ± 529 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"4.65 ms ± 601 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"7.25 ms ± 602 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"12 ms ± 1.27 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"18.7 ms ± 1.36 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"30.7 ms ± 3.21 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"63.5 ms ± 22.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"115 ms ± 38.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"130 ms ± 9.28 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"251 ms ± 50.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"392 ms ± 73.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n",
|
|
"629 ms ± 104 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"times = []\n",
|
|
"for i in range(33):\n",
|
|
" t = %timeit -n1 -o f(i)\n",
|
|
" times.append(t.best)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 34,
|
|
"id": "demanding-circulation",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>f</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1.580001e-07</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>1.819999e-07</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>1.979997e-07</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>4.560002e-07</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>7.710000e-07</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" f\n",
|
|
"0 1.580001e-07\n",
|
|
"1 1.819999e-07\n",
|
|
"2 1.979997e-07\n",
|
|
"3 4.560002e-07\n",
|
|
"4 7.710000e-07"
|
|
]
|
|
},
|
|
"execution_count": 34,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"df = pd.DataFrame(data=times, columns=[\"f\"])\n",
|
|
"df.head()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 36,
|
|
"id": "complete-warren",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAE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IBARyXP/HylqPccc8btDAAAAAElFTkSuQmCC\n",
|
|
"text/plain": [
|
|
"<Figure size 432x288 with 1 Axes>"
|
|
]
|
|
},
|
|
"metadata": {
|
|
"needs_background": "light"
|
|
},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"import matplotlib.pyplot as plt\n",
|
|
"\n",
|
|
"g = df.plot(title=\"F time\")\n",
|
|
"g.set_xlabel(\"n\")\n",
|
|
"g.set_ylabel(\"time (s)\")\n",
|
|
"plt.savefig(\"f.png\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"id": "empirical-tolerance",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"f 3.693825\n",
|
|
"dtype: float64"
|
|
]
|
|
},
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"df.sum()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "dress-series",
|
|
"metadata": {},
|
|
"source": [
|
|
"### More data types - Dictionaries"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 68,
|
|
"id": "fifth-stereo",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"dct = {\n",
|
|
" \"key1\": \"value1\",\n",
|
|
" \"key2\": [\"value2\", \"value3\"],\n",
|
|
" \"random name for a key\": 1,\n",
|
|
" \"key4\": (2000, 3000)\n",
|
|
"}"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 42,
|
|
"id": "periodic-estate",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"(2000, 3000)"
|
|
]
|
|
},
|
|
"execution_count": 42,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"dct[\"key4\"]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 45,
|
|
"id": "buried-plant",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"#dct['key5'] will error"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 50,
|
|
"id": "precise-possession",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"True"
|
|
]
|
|
},
|
|
"execution_count": 50,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"dct.get(\"key5\") is None"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 70,
|
|
"id": "perfect-commander",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"key: key1, value: value1\n",
|
|
"key: key2, value: ['value2', 'value3']\n",
|
|
"key: random name for a key, value: 1\n",
|
|
"key: key4, value: (2000, 3000)\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"for k,v in dct.items():\n",
|
|
" print(f\"key: {k}, value: {v}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 91,
|
|
"id": "prompt-maldives",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"cache = {}\n",
|
|
"\n",
|
|
"def f_better(n: int) -> int:\n",
|
|
" \"\"\"\n",
|
|
" Fibonacci sequence - !!with caching!!\n",
|
|
" ---\n",
|
|
" params\n",
|
|
" n (int) number requested in sequence\n",
|
|
" \n",
|
|
" returns\n",
|
|
" interger in fibonacci sequence\n",
|
|
" \"\"\"\n",
|
|
" if all([cache.get(n-1), cache.get(n-2)]):\n",
|
|
" return cache[n-1] + cache[n-2] \n",
|
|
" elif n == 0:\n",
|
|
" return 0\n",
|
|
" elif n == 1 or n == 2:\n",
|
|
" return 1\n",
|
|
" else:\n",
|
|
" cache[n] = f_better(n-1) + f_better(n-2) \n",
|
|
" return cache[n]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 92,
|
|
"id": "north-logistics",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>f</th>\n",
|
|
" <th>f_better</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1.580001e-07</td>\n",
|
|
" <td>0.000001</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>1.819999e-07</td>\n",
|
|
" <td>0.000001</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>1.979997e-07</td>\n",
|
|
" <td>0.000001</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>4.560002e-07</td>\n",
|
|
" <td>0.000003</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>7.710000e-07</td>\n",
|
|
" <td>0.000006</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" f f_better\n",
|
|
"0 1.580001e-07 0.000001\n",
|
|
"1 1.819999e-07 0.000001\n",
|
|
"2 1.979997e-07 0.000001\n",
|
|
"3 4.560002e-07 0.000003\n",
|
|
"4 7.710000e-07 0.000006"
|
|
]
|
|
},
|
|
"execution_count": 92,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"times = []\n",
|
|
"for i in range(35):\n",
|
|
" t = %timeit -n1 -o -q f_better(i)\n",
|
|
" times.append(t.best)\n",
|
|
" \n",
|
|
"df['f_better'] = pd.DataFrame(data=times)\n",
|
|
"df.head()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 93,
|
|
"id": "honest-rings",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEWCAYAAABrDZDcAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAiQ0lEQVR4nO3de3xcdZ3/8dcnadK0TXpPIWlaUkqBtlyKlHrpriCCUJHWu/DTFdAVUHiIsvtYi64K7K66wuriCmJ14YcKVmRdqP6KoEAFdhfbwJbSJC0tpbmQ0rQJbZqkuX9+f8xMGdJJMk1ycubyfj4e85g5lznnk0k775zv95zvMXdHRESyV07YBYiISLgUBCIiWU5BICKS5RQEIiJZTkEgIpLlFAQiIllOQSAyQmb2VTP7adh1iAyX6ToCETCz3cBxQG/c7JPdvaHfeucBv3D3sjErTiRg48IuQCSFXOrufwy7CJGxpqYhkSSZ2STgUaDUzFqjj1Izu9nMfhFdp9zM3MyuMrM6M3vDzK41s3PMbIuZHTCzH/bb7mfMrDq67mNmdkIYP59kLwWBSJLcvQ1YATS4e2H00TDA6m8HFgCfAP4V+BpwAbAY+LiZnQtgZh8Evgp8GCgGngF+GeCPIXIUBYHImx6O/sV+wMweHuG2/sHdO9z9caAN+KW7N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jsz+DSGdwLpE/sh9091uj/4fXAtOB/wU+5e6d4VV6tKwJAhERSSxbmoZERGQACgIRkSynIBARyXIKAhGRLKcgEBHJcgoCEZEspyAQEclyCgKRETKz8ugY+j+JjkP/ePTKUpG0oCAQGR0LgDvdfTFwAPhIuOWIJE9BIDI6XnX3zdHXzwPl4ZUicmwUBCKjI37smF4i40KJpAUFgYhIllMQiIhkOY0+KiKS5XREICKS5RQEIiJZTkEgIpLlFAQiIllOQSAikuUUBCIiWU5BICKS5f4/ALVPwYLlURcAAAAASUVORK5CYII=\n",
|
|
"text/plain": [
|
|
"<Figure size 432x288 with 1 Axes>"
|
|
]
|
|
},
|
|
"metadata": {
|
|
"needs_background": "light"
|
|
},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"g = df.plot(title=\"F time\")\n",
|
|
"g.set_xlabel(\"n\")\n",
|
|
"g.set_ylabel(\"time (s)\")\n",
|
|
"plt.savefig(\"f_better.png\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 83,
|
|
"id": "egyptian-seminar",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{3: 2,\n",
|
|
" 4: 3,\n",
|
|
" 6: 8,\n",
|
|
" 7: 13,\n",
|
|
" 9: 34,\n",
|
|
" 10: 55,\n",
|
|
" 12: 144,\n",
|
|
" 13: 233,\n",
|
|
" 15: 610,\n",
|
|
" 16: 987,\n",
|
|
" 18: 2584,\n",
|
|
" 19: 4181,\n",
|
|
" 21: 10946,\n",
|
|
" 22: 17711,\n",
|
|
" 24: 46368,\n",
|
|
" 25: 75025,\n",
|
|
" 27: 196418,\n",
|
|
" 28: 317811,\n",
|
|
" 30: 832040,\n",
|
|
" 31: 1346269,\n",
|
|
" 33: 3524578,\n",
|
|
" 34: 5702887}"
|
|
]
|
|
},
|
|
"execution_count": 83,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"cache"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "loving-jungle",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Classes"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 133,
|
|
"id": "parallel-sharp",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class Car:\n",
|
|
" \"\"\"\n",
|
|
" Class for cars that people drive\n",
|
|
" ---\n",
|
|
" params \n",
|
|
" make (str): make of the car\n",
|
|
" model (str): model of the car\n",
|
|
" year (int): year car was made\n",
|
|
" \"\"\"\n",
|
|
" def __init__(self, make: str, model: str, year: int=2021):\n",
|
|
" self.make = make\n",
|
|
" self.model = model\n",
|
|
" self.year = year\n",
|
|
" self.__is_driving = False\n",
|
|
" \n",
|
|
" def __repr__(self):\n",
|
|
" return f'{self.make} - {self.model}'\n",
|
|
" \n",
|
|
" def drive(self) -> str:\n",
|
|
" if not self.__is_driving:\n",
|
|
" print(f'{self.make} - {self.model} is now driving')\n",
|
|
" self.__is_driving = True\n",
|
|
" else:\n",
|
|
" print(f'{self.make} - {self.model} is ALREADY driving!')\n",
|
|
" \n",
|
|
" def stop(self) -> str:\n",
|
|
" if self.__is_driving:\n",
|
|
" print(f'{self.make} - {self.model} has stopped')\n",
|
|
" self.__is_driving = False\n",
|
|
" else:\n",
|
|
" print(f'{self.make} - {self.model} is ALREADY stopped!')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 134,
|
|
"id": "protective-lying",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"\u001b[0;31mInit signature:\u001b[0m \u001b[0mCar\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmake\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0myear\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mint\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2021\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0;31mDocstring:\u001b[0m \n",
|
|
"Class for cars that people drive\n",
|
|
"---\n",
|
|
"params \n",
|
|
" make (str): make of the car\n",
|
|
" model (str): model of the car\n",
|
|
" year (int): year car was made\n",
|
|
"\u001b[0;31mType:\u001b[0m type\n",
|
|
"\u001b[0;31mSubclasses:\u001b[0m \n"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"?Car"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 135,
|
|
"id": "dimensional-shanghai",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"shivan = Car('Toyota', 'Corolla', '2008')\n",
|
|
"bruno = Car('Tesla', 'Model3')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 136,
|
|
"id": "raised-brook",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Tesla - Model3"
|
|
]
|
|
},
|
|
"execution_count": 136,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"bruno"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 137,
|
|
"id": "earlier-diploma",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Toyota - Corolla is now driving\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"shivan.drive()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 138,
|
|
"id": "varied-setting",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Toyota - Corolla is ALREADY driving!\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"shivan.drive()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 139,
|
|
"id": "recognized-forwarding",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Tesla - Model3 is ALREADY stopped!\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"bruno.stop()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "executed-cleanup",
|
|
"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.10"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|