Fix after wierd merge

pull/10/head
Tim Skov Jacobsen 2019-12-03 10:41:09 +01:00
parent 0fcb6d8a00
commit c4d4abcb6b
1 changed files with 334 additions and 91 deletions

View File

@ -676,7 +676,7 @@
{
"data": {
"text/plain": [
"1964944755848"
"2929687412616"
]
},
"execution_count": 20,
@ -696,7 +696,7 @@
{
"data": {
"text/plain": [
"1964944755848"
"2929687412616"
]
},
"execution_count": 21,
@ -852,8 +852,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"x_new has object id: 1964944643784 \n",
"y_new has object id: 1964945169544\n"
"x_new has object id: 2929687753800 \n",
"y_new has object id: 2929687504072\n"
]
}
],
@ -890,15 +890,11 @@
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n"
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-28-2d3eb657ed9c>, line 3)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-28-2d3eb657ed9c>\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m print(num))\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
@ -959,13 +955,17 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "superman\nspiderman\ngreen lantern\n"
"text": [
"superman\n",
"spiderman\n",
"green lantern\n"
]
}
],
"source": [
@ -978,22 +978,24 @@
},
{
"cell_type": "markdown",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Note how for-loops in Python can avoid dealing with indexes, while still supporting the alternative."
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "superman\nspiderman\ngreen lantern\n"
"text": [
"superman\n",
"spiderman\n",
"green lantern\n"
]
}
],
"source": [
@ -1005,18 +1007,7 @@
},
{
"cell_type": "markdown",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-2-4d251609901f>, line 2)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-2-4d251609901f>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m A `while` loop is a loop that continues until some condition is no longer satisfied.\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"## `while` loops\n",
"A `while` loop is a loop that continues until some condition is no longer satisfied.\n",
@ -1046,7 +1037,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 32,
"metadata": {},
"outputs": [
{
@ -1085,22 +1076,25 @@
},
{
"cell_type": "markdown",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Both for and while loops can be affected by `continue` and/or `break`. `Continue` starts on the next interation while skipping the rest of the code block and `break` stops the whole loop. The example above is reproduced below using `break`. This can sometime yield more readable code."
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "The count is 1\nThe count is 2\nThe count is 3\nThe count is 4\n"
"text": [
"The count is 1\n",
"The count is 2\n",
"The count is 3\n",
"The count is 4\n"
]
}
],
"source": [
@ -1142,7 +1136,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 34,
"metadata": {},
"outputs": [
{
@ -1151,7 +1145,7 @@
"[24, 430, 62, 874, 102]"
]
},
"execution_count": 32,
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
@ -1174,7 +1168,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 35,
"metadata": {},
"outputs": [
{
@ -1183,7 +1177,7 @@
"[12, 215, 31, 437, 51, 12, 215, 31, 437, 51]"
]
},
"execution_count": 33,
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
@ -1199,53 +1193,6 @@
"To get a vectorized behavior like that we could have used `numpy`, which is a hugely popular third party library for numerical compuations similar to Matlab. Later sessions will explore `numpy` further."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercise 7\n",
"From the following list, create a new list containing only the elements that have exactly five characters. \n",
"~~~python\n",
"phonetic_alphabet = ['Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot']\n",
"~~~"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercise 8\n",
"Find the intersection of the two sets (elements that occur in both sets)\n",
"~~~python\n",
"s1 = {'HE170B', 'HE210B', 'HE190A', 'HE200A', 'HE210A', 'HE210A'}\n",
"\n",
"s2 = {'HE200A', 'HE210A', 'HE240A', 'HE200A', 'HE210B', 'HE340A'}\n",
"~~~"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": "[4, 5]"
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Exercise 9\n",
"Create a variable `fy` and set it equal to 435.\n",
"\n",
"# Filter list with list comprehension by use of condition\n",
"result_list = [x for x in x if x > 3]\n",
"result_list"
]
},
{
"cell_type": "markdown",
"metadata": {},
@ -1276,14 +1223,16 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": "[None, None, 182, None, 151, 174]"
"text/plain": [
"[None, None, 182, None, 151, 174]"
]
},
"execution_count": 10,
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
@ -1444,6 +1393,300 @@
"T1 = (-18, -27, 2, -21, -15, 5)\n",
"~~~"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# End of exercises\n",
"\n",
"*The cell below is for setting the style of this document. It's not part of the exercises.*"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>\n",
"/* div#notebook {\n",
" font-size: 13pt;\n",
" line-height: 120%;\n",
" color: #303030;\n",
" -webkit-font-smoothing: antialiased !important;\n",
" padding-top: 25px !important;\n",
"} */\n",
"\n",
"\n",
"body,\n",
"div.body {\n",
" font-family: Roboto;\n",
" /* font-size: 16pt; */\n",
" color: #303030;\n",
" /* background-color: #d1b5b5; */\n",
" /* background: #8f4f4f; */\n",
" margin-right: 10px;\n",
" /* -webkit-font-smoothing: antialiased !important; */\n",
"}\n",
"\n",
"/* Code inside HTML/Markdown */\n",
"div.rendered_html code {\n",
" border-radius: 5px;\n",
"}\n",
"\n",
"/* Output area from code cells */\n",
"div.output_area pre {\n",
" /* font-size: 11pt !important; */\n",
" color: #303030;\n",
"}\n",
"\n",
"\n",
"\n",
"/* HEADING 1 styles */\n",
"h1 {\n",
" font-family: 'Roboto', 'Signika', sans-serif;\n",
" font-weight: ligher;\n",
" font-style: normal;\n",
" /* font-size: 20pt; */\n",
" width: 100%;\n",
" text-align: left;\n",
" color: #EE7631;\n",
" border-bottom: 1px solid rgba(238, 118, 49, 0.575);\n",
" padding-bottom: 6px;\n",
" /* font-variant: small-caps; */\n",
" }\n",
" \n",
" /* table {\n",
" margin: 5px;\n",
" width: 290px;\n",
" }\n",
" \n",
" th {\n",
" padding: 3px;\n",
" }\n",
" \n",
" td {\n",
" padding-left: 8px;\n",
" padding-right: 8px;\n",
" border: 1px solid #990000;\n",
" background-color: #ffffcc;\n",
" }\n",
"\n",
" #trHeader {\n",
" text-decoration: underline;\n",
" color: #990000;\n",
" }\n",
" \n",
" .centerCell {\n",
" text-align: center;\n",
" } */\n",
"\n",
"/* HEADING 2 styles */\n",
"h2 {\n",
" font-family: \"Roboto\";\n",
" text-align: left;\n",
" /* font-size: 12pt; */\n",
" color: #EE7631;\n",
" margin-bottom: 5px;\n",
" /* border-bottom: 1px solid lightgray; */\n",
" border-bottom: 0.8px solid rgba(238, 118, 49, 0.575);\n",
" padding-bottom: 6px\n",
" }\n",
" \n",
" /* table {\n",
" margin: 5px;\n",
" width: 290px;\n",
" }\n",
" \n",
" th {\n",
" padding: 3px;\n",
" }\n",
" \n",
" td {\n",
" padding-left: 8px;\n",
" padding-right: 8px;\n",
" border: 1px solid #990000;\n",
" background-color: #ffffcc;\n",
" }\n",
"\n",
" #trHeader {\n",
" text-decoration: underline;\n",
" color: #990000;\n",
" }\n",
" \n",
" .centerCell {\n",
" text-align: center;\n",
" } */\n",
"\n",
"h3 {\n",
" font-family: 'Roboto';\n",
" /* text-align: left; */\n",
" /* font-size: 12pt; */\n",
" /* color: #EE7631; */\n",
" /* margin-bottom: 5px; */\n",
" border-bottom: 0.5px solid #ededed;\n",
" padding-bottom: 6px\n",
" }\n",
"\n",
"\n",
"\n",
"p {\n",
" font-family: Roboto;\n",
" font-size: 16px;\n",
"}\n",
"\n",
"/* Lists with dots */\n",
"ul {\n",
" font-size: 16px;\n",
" line-height: 150%;\n",
"}\n",
"\n",
"/* Lists with numbers */\n",
"ol {\n",
" font-size: 16px;\n",
" line-height: 150%;\n",
"}\n",
"\n",
"/* Horizontal rules */\n",
"hr { \n",
" margin-top: 3px; \n",
" margin-bottom: 3px \n",
"}\n",
"\n",
"/* Links */\n",
"a {\n",
" color: #EE7631;\n",
"}\n",
"\n",
"\n",
"/* Change global font size (for code) */\n",
".CodeMirror {\n",
"font-size: 16px !important;\n",
"font-family: monospace;\n",
"}\n",
"\n",
"\n",
"/* Code cells in the notebook - NOTE: color is font-color */\n",
".cm-s-ipython.CodeMirror {\n",
" font-family: monospace, monospace;\n",
" /* font-size: 11pt; */\n",
" background: #ededed;\n",
" color: #303030; \n",
" border-radius: 2px;\n",
" /* margin-right: 10px; */\n",
" font-style: normal;\n",
" font-weight: normal;\n",
"}\n",
"\n",
"\n",
"/* Background of code cells */\n",
".cm-s-ipython.CodeMirror {\n",
" font-family: monospace, monospace;\n",
" /* font-size: 11pt; */\n",
" background: rgba(211, 211, 211, 0.123);\n",
" color: #303030;\n",
" border-radius: 2px;\n",
" font-style: normal;\n",
" font-weight: normal;\n",
"}\n",
"\n",
"\n",
"/* .CodeMirror-gutters {\n",
" border: none;\n",
" border-right: 1px solid #e0e1e3 !important;\n",
" background-color: #e0e1e3 !important;\n",
" background: #e0e1e3 !important;\n",
" border-radius: 0px;\n",
" white-space: nowrap;\n",
"} */\n",
"\n",
"\n",
"\n",
"/* Code syntax highlithig theme */\n",
".cm-s-ipython .CodeMirror-cursor {\n",
" border-left: 2px solid #ff711a !important;\n",
"}\n",
".cm-s-ipython span.cm-comment {\n",
" color: #8d8d8d;\n",
" font-style: italic; \n",
"}\n",
".cm-s-ipython span.cm-atom {\n",
" color: #055be0;\n",
"}\n",
".cm-s-ipython span.cm-number {\n",
" color: #ff8132;\n",
"}\n",
".cm-s-ipython span.cm-property {\n",
" color: #303030;\n",
"}\n",
".cm-s-ipython span.cm-attribute {\n",
" color: #303030;\n",
"}\n",
".cm-s-ipython span.cm-keyword {\n",
" color: #a045ddf3;\n",
" font-weight: normal;\n",
"}\n",
".cm-s-ipython span.cm-string {\n",
" color: #009e07;\n",
"}\n",
".cm-s-ipython span.cm-meta {\n",
" color: #aa22ff;\n",
"}\n",
".cm-s-ipython span.cm-operator {\n",
" color: #055be0;\n",
"}\n",
".cm-s-ipython span.cm-builtin {\n",
" color: #3f2ce7;\n",
"}\n",
".cm-s-ipython span.cm-variable {\n",
" color: #303030;\n",
"}\n",
".cm-s-ipython span.cm-variable-2 {\n",
" color: #de143d;\n",
"}\n",
".cm-s-ipython span.cm-variable-3 {\n",
" color: #aa22ff;\n",
"}\n",
".cm-s-ipython span.cm-def {\n",
" color: #e22978;\n",
" font-weight: normal;\n",
"}\n",
".cm-s-ipython span.cm-error {\n",
" background: rgba(191,11,55,.70);\n",
"}\n",
".cm-s-ipython span.cm-tag {\n",
" color: #e22978;\n",
"}\n",
".cm-s-ipython span.cm-link {\n",
" color: #ef5c00;\n",
"}\n",
".cm-s-ipython span.cm-storage {\n",
" color: #055be0;\n",
"}\n",
".cm-s-ipython span.cm-entity {\n",
" color: #e22978;\n",
"}\n",
".cm-s-ipython span.cm-quote {\n",
" color: #009e07;\n",
"}\n",
"</style>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import HTML\n",
"HTML('<style>{}</style>'.format(open('../css/cowi.css').read()))"
]
}
],
"metadata": {
@ -1463,7 +1706,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.4"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
@ -1507,4 +1750,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}