From 02595ec32a3a076ed02901490055e75101b96f60 Mon Sep 17 00:00:00 2001 From: TJ Lamba Date: Fri, 10 May 2024 15:00:41 -0400 Subject: [PATCH] rand msg --- 01_slides/08_control_flow.ipynb | 370 +++++++++++++++++++++++++----- 01_slides/11_numpy.ipynb | 20 +- 02_assignments/assignment_1.ipynb | 10 +- 02_assignments/assignment_2.ipynb | 174 +++++++++++--- 4 files changed, 485 insertions(+), 89 deletions(-) diff --git a/01_slides/08_control_flow.ipynb b/01_slides/08_control_flow.ipynb index b7fda3d7c..6d347fe90 100644 --- a/01_slides/08_control_flow.ipynb +++ b/01_slides/08_control_flow.ipynb @@ -1792,7 +1792,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "03a4588b", "metadata": { "colab": { @@ -1801,7 +1801,18 @@ "id": "03a4588b", "outputId": "db2c020b-5558-495d-f82a-000a54f258cf" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "('changeable', 'fluctuating', 'inconstant', 'variable')" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "mutable_synonyms = ('changeable', 'fluctuating', 'inconstant', 'variable')\n", "mutable_synonyms" @@ -1819,7 +1830,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "dd7866e6", "metadata": { "colab": { @@ -1828,7 +1839,18 @@ "id": "dd7866e6", "outputId": "52c5b256-f870-4cec-c3a5-08f6fddcb2b1" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "tuple" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "empty = ()\n", "type(empty)" @@ -1836,7 +1858,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "a1455b74", "metadata": { "colab": { @@ -1845,7 +1867,18 @@ "id": "a1455b74", "outputId": "b6dcd6c9-d457-4ae3-e352-7ee2e6fb2d1c" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "tuple" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "also_empty = tuple()\n", "type(also_empty)" @@ -1853,7 +1886,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "3b7b303b", "metadata": { "colab": { @@ -1863,7 +1896,19 @@ "id": "3b7b303b", "outputId": "70b57f43-fc66-48f2-9968-80e05d2b1d98" }, - "outputs": [], + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'tuple' object has no attribute 'append'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[4], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# not an actual tuple method\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[43mempty\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mappend\u001b[49m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhi\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", + "\u001b[1;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'append'" + ] + } + ], "source": [ "# not an actual tuple method\n", "empty.append('hi')" @@ -2167,7 +2212,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "31a4a0b4", "metadata": { "id": "31a4a0b4" @@ -2180,7 +2225,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "77906906", "metadata": { "colab": { @@ -2189,7 +2234,16 @@ "id": "77906906", "outputId": "4a75c52f-5926-4416-ac54-ee8a2e4f17d7" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "In the rainbow but not the Olympic flag: {'indigo', 'violet', 'orange'}\n", + "In the Olympic flag but not the rainbow: {'black'}\n" + ] + } + ], "source": [ "print(f'In the rainbow but not the Olympic flag: {rainbow.difference(olympic_flag)}')\n", "print(f'In the Olympic flag but not the rainbow: {olympic_flag.difference(rainbow)}')" @@ -2197,7 +2251,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "0f70aa26", "metadata": { "colab": { @@ -2206,14 +2260,22 @@ "id": "0f70aa26", "outputId": "83ace290-4513-4913-9306-65125f4a1db5" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Only in one: {'violet', 'black', 'orange', 'indigo'}\n" + ] + } + ], "source": [ "print(f'Only in one: {rainbow.symmetric_difference(olympic_flag)}')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "eca13bed", "metadata": { "colab": { @@ -2222,14 +2284,22 @@ "id": "eca13bed", "outputId": "062f832d-8d79-4d41-a1ca-66bfc42b9551" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Common colours : {'green', 'yellow', 'red', 'blue'}\n" + ] + } + ], "source": [ "print(f'Common colours : {rainbow.intersection(olympic_flag)}')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "26c9bc0d", "metadata": { "colab": { @@ -2238,7 +2308,15 @@ "id": "26c9bc0d", "outputId": "e9e5ba5e-cb7d-4354-c046-cfd51769e363" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "All colours: {'violet', 'orange', 'red', 'indigo', 'green', 'yellow', 'black', 'blue'}\n" + ] + } + ], "source": [ "print(f'All colours: {rainbow.union(olympic_flag)}')" ] @@ -2269,7 +2347,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "4ebcf461", "metadata": { "colab": { @@ -2278,7 +2356,20 @@ "id": "4ebcf461", "outputId": "ce3ccb1a-f249-4845-aa64-5fcc9996afb1" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'Canada': 'Ottawa',\n", + " 'United States': 'Washington, D.C.',\n", + " 'Mexico': 'Mexico City'}" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "capitals = {'Canada': 'Ottawa',\n", " 'United States': 'Washington, D.C.',\n", @@ -2288,7 +2379,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "26204e75", "metadata": { "colab": { @@ -2297,7 +2388,18 @@ "id": "26204e75", "outputId": "2af033a8-3ceb-45e7-f244-9dc62ba4679d" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{2020: 'Tokyo', 2016: 'Rio de Janiero', 2012: 'London'}" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "olympics_cities = {2020: 'Tokyo', 2016: 'Rio de Janiero', 2012: 'London'}\n", "olympics_cities" @@ -2315,7 +2417,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "9567a42f", "metadata": { "colab": { @@ -2324,7 +2426,19 @@ "id": "9567a42f", "outputId": "59470523-941a-4b35-e046-ee0f1ced7e41" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'summer': {2020: 'Tokyo', 2016: 'Rio de Janiero', 2012: 'London'},\n", + " 'winter': {2022: 'Beijing', 2018: 'Pyeongchang'}}" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "all_olympics_hosts = {'summer': olympics_cities,\n", " 'winter': {2022: 'Beijing', 2018: 'Pyeongchang'}}\n", @@ -2343,7 +2457,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "id": "82ea8a74", "metadata": { "colab": { @@ -2352,7 +2466,18 @@ "id": "82ea8a74", "outputId": "3bac7409-d1a3-4f64-d8c7-4cf77c69728e" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "dict" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "empty_dictionary = {}\n", "type(empty_dictionary)" @@ -2360,7 +2485,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "id": "740e8ab8", "metadata": { "colab": { @@ -2369,7 +2494,18 @@ "id": "740e8ab8", "outputId": "75013ccf-664c-4fb1-8b6e-8462b6cf3270" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "dict" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "still_empty = dict()\n", "type(still_empty)" @@ -2389,7 +2525,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "id": "d8c5c78b", "metadata": { "colab": { @@ -2399,14 +2535,25 @@ "id": "d8c5c78b", "outputId": "2702af14-b7b7-4bb5-ca16-a039638df12b" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Rio de Janiero'" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "olympics_cities[2016]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "id": "8c3ef741", "metadata": { "colab": { @@ -2416,7 +2563,18 @@ "id": "8c3ef741", "outputId": "6b4ae8be-a240-429e-920d-a89bac3af54b" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Pyeongchang'" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "all_olympics_hosts['winter'][2018]" ] @@ -2433,7 +2591,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "id": "22e5885c", "metadata": { "colab": { @@ -2443,7 +2601,19 @@ "id": "22e5885c", "outputId": "5411f9dc-8829-4d84-e398-4e57d5b42e86" }, - "outputs": [], + "outputs": [ + { + "ename": "KeyError", + "evalue": "2014", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[30], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43molympics_cities\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m2014\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[1;31mKeyError\u001b[0m: 2014" + ] + } + ], "source": [ "olympics_cities[2014]" ] @@ -2805,7 +2975,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "id": "e01cb12f", "metadata": { "colab": { @@ -2814,7 +2984,21 @@ "id": "e01cb12f", "outputId": "34037d18-ff0e-42eb-9359-ce6c66ac1c66" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['processed_data_01.xlsx',\n", + " 'processed_data_02.xlsx',\n", + " 'processed_data_03.xlsx',\n", + " 'processed_data_04.xlsx']" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "input_files = ['data_01.csv', 'data_02.csv', 'data_03.csv', 'data_04.csv']\n", "output_files = []\n", @@ -2840,7 +3024,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "id": "dbf18fa4", "metadata": { "colab": { @@ -2849,7 +3033,19 @@ "id": "dbf18fa4", "outputId": "bcedc555-debf-4cdb-b3ec-6d9c7340d303" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Stop 1 is Sheppard-Yonge.\n", + "Stop 2 is Bayview.\n", + "Stop 3 is Bessarion.\n", + "Stop 4 is Leslie.\n", + "Stop 5 is Don Mills.\n" + ] + } + ], "source": [ "stops = ['Sheppard-Yonge', 'Bayview', 'Bessarion', 'Leslie', 'Don Mills']\n", "for idx, stop in enumerate(stops):\n", @@ -2858,7 +3054,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "id": "dffcff90", "metadata": { "colab": { @@ -2867,7 +3063,18 @@ "id": "dffcff90", "outputId": "66fddd3f-ce24-4ee7-a35f-eecb055e64d1" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 20, 200, 2000]" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# double a list in place\n", "numbers = [1, 10, 100, 1000]\n", @@ -2890,7 +3097,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "id": "1df5c753", "metadata": { "colab": { @@ -2899,7 +3106,17 @@ "id": "1df5c753", "outputId": "b670d4e9-cfe5-42cc-869d-7f7e9078d0df" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(43.65, -79.38)\n", + "(45.52, -73.57)\n", + "(49.28, -123.13)\n" + ] + } + ], "source": [ "lats = (43.650, 45.520, 49.280)\n", "lons = (-79.380, -73.570, -123.130)\n", @@ -2924,7 +3141,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "id": "d2fa7beb", "metadata": { "colab": { @@ -2933,7 +3150,19 @@ "id": "d2fa7beb", "outputId": "ca56c393-9ee3-42ee-a23a-0de4f0b60318" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The 2020 Summer Olympics were in Tokyo.\n", + "The 2016 Summer Olympics were in Rio de Janiero.\n", + "The 2012 Summer Olympics were in London.\n", + "The 2022 Winter Olympics were in Beijing.\n", + "The 2018 Winter Olympics were in Pyeongchang.\n" + ] + } + ], "source": [ "for key, value in all_olympics_hosts.items():\n", " for year, city in value.items():\n", @@ -2942,7 +3171,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "id": "123ca926", "metadata": { "id": "123ca926" @@ -2975,7 +3204,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "id": "26858eb7", "metadata": { "colab": { @@ -2984,7 +3213,20 @@ "id": "26858eb7", "outputId": "f9738465-5d8b-415a-9571-746ea265717a" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\t1\t2\t3\t4\t5\n", + "1\t1\t2\t3\t4\t5\n", + "2\t2\t4\t6\t8\t10\n", + "3\t3\t6\t9\t12\t15\n", + "4\t4\t8\t12\t16\t20\n", + "5\t5\t10\t15\t20\t25\n" + ] + } + ], "source": [ "print_table(5)" ] @@ -3003,7 +3245,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "755633ee", "metadata": { "colab": { @@ -3012,7 +3254,18 @@ "id": "755633ee", "outputId": "0cda116b-fb50-4f7b-9190-295581c803cd" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "3\n", + "2\n", + "1\n" + ] + } + ], "source": [ "countdown = 4\n", "\n", @@ -3037,7 +3290,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "bab8a554", "metadata": { "id": "bab8a554" @@ -3075,7 +3328,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "b497e524", "metadata": { "colab": { @@ -3084,7 +3337,18 @@ "id": "b497e524", "outputId": "7e839855-8907-442d-e2d1-4de8990f8caa" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "3\n", + "We are breaking the loop early.\n", + "Done iterating.\n" + ] + } + ], "source": [ "countdown = 4\n", "\n", @@ -3110,7 +3374,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "055270c4", "metadata": { "colab": { @@ -3214,7 +3478,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.9.15" }, "rise": { "scroll": true, diff --git a/01_slides/11_numpy.ipynb b/01_slides/11_numpy.ipynb index 134109f3c..b90d3b76a 100644 --- a/01_slides/11_numpy.ipynb +++ b/01_slides/11_numpy.ipynb @@ -94,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "cea5f938", "metadata": { "id": "cea5f938" @@ -120,7 +120,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "cf533fdd", "metadata": { "colab": { @@ -129,7 +129,19 @@ "id": "cf533fdd", "outputId": "4ad1a1e1-cab0-4f5b-c3af-2a3412e15c42" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1, 2, 3],\n", + " [3, 2, 1]])" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a = np.array([[1, 2, 3],\n", " [3, 2, 1]])\n", @@ -1560,7 +1572,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.9.15" }, "rise": { "scroll": true, diff --git a/02_assignments/assignment_1.ipynb b/02_assignments/assignment_1.ipynb index 992c0ccf2..c703d77d4 100644 --- a/02_assignments/assignment_1.ipynb +++ b/02_assignments/assignment_1.ipynb @@ -124,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -153,7 +153,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -162,7 +162,7 @@ "False" ] }, - "execution_count": 12, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -173,7 +173,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -182,7 +182,7 @@ "True" ] }, - "execution_count": 13, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } diff --git a/02_assignments/assignment_2.ipynb b/02_assignments/assignment_2.ipynb index 77554f12b..ca7e24bc7 100644 --- a/02_assignments/assignment_2.ipynb +++ b/02_assignments/assignment_2.ipynb @@ -39,10 +39,10 @@ " * Open a private window in your browser. Copy and paste the link to your pull request into the address bar. Make sure you can see your pull request properly. This helps the technical facilitator and learning support staff review your submission easily.\n", "\n", "Checklist:\n", - "- [ ] Created a branch with the correct naming convention.\n", - "- [ ] Ensured that the repository is public.\n", - "- [ ] Reviewed the PR description guidelines and adhered to them.\n", - "- [ ] Verify that the link is accessible in a private browser window.\n", + "- [ x ] Created a branch with the correct naming convention.\n", + "- [ x ] Ensured that the repository is public.\n", + "- [ x ] Reviewed the PR description guidelines and adhered to them.\n", + "- [ x ] Verify that the link is accessible in a private browser window.\n", "\n", "If you encounter any difficulties or have questions, please don't hesitate to reach out to our team via our Slack at `#cohort-3-help`. Our Technical Facilitators and Learning Support staff are here to help you navigate any challenges." ] @@ -90,15 +90,112 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "n0m48JsS-nMC" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Contents of ../05_data/assignment_2_data/inflammation_01.csv:\n", + "0,0,1,3,1,2,4,7,8,3,3,3,10,5,7,4,7,7,12,18,6,13,11,11,7,7,4,6,8,8,4,4,5,7,3,4,2,3,0,0\n", + "0,1,2,1,2,1,3,2,2,6,10,11,5,9,4,4,7,16,8,6,18,4,12,5,12,7,11,5,11,3,3,5,4,4,5,5,1,1,0,1\n", + "0,1,1,3,3,2,6,2,5,9,5,7,4,5,4,15,5,11,9,10,19,14,12,17,7,12,11,7,4,2,10,5,4,2,2,3,2,2,1,1\n", + "0,0,2,0,4,2,2,1,6,7,10,7,9,13,8,8,15,10,10,7,17,4,4,7,6,15,6,4,9,11,3,5,6,3,3,4,2,3,2,1\n", + "0,1,1,3,3,1,3,5,2,4,4,7,6,5,3,10,8,10,6,17,9,14,9,7,13,9,12,6,7,7,9,6,3,2,2,4,2,0,1,1\n", + "0,0,1,2,2,4,2,1,6,4,7,6,6,9,9,15,4,16,18,12,12,5,18,9,5,3,10,3,12,7,8,4,7,3,5,4,4,3,2,1\n", + "0,0,2,2,4,2,2,5,5,8,6,5,11,9,4,13,5,12,10,6,9,17,15,8,9,3,13,7,8,2,8,8,4,2,3,5,4,1,1,1\n", + "0,0,1,2,3,1,2,3,5,3,7,8,8,5,10,9,15,11,18,19,20,8,5,13,15,10,6,10,6,7,4,9,3,5,2,5,3,2,2,1\n", + "0,0,0,3,1,5,6,5,5,8,2,4,11,12,10,11,9,10,17,11,6,16,12,6,8,14,6,13,10,11,4,6,4,7,6,3,2,1,0,0\n", + "0,1,1,2,1,3,5,3,5,8,6,8,12,5,13,6,13,8,16,8,18,15,16,14,12,7,3,8,9,11,2,5,4,5,1,4,1,2,0,0\n", + "0,1,0,0,4,3,3,5,5,4,5,8,7,10,13,3,7,13,15,18,8,15,15,16,11,14,12,4,10,10,4,3,4,5,5,3,3,2,2,1\n", + "0,1,0,0,3,4,2,7,8,5,2,8,11,5,5,8,14,11,6,11,9,16,18,6,12,5,4,3,5,7,8,3,5,4,5,5,4,0,1,1\n", + "0,0,2,1,4,3,6,4,6,7,9,9,3,11,6,12,4,17,13,15,13,12,8,7,4,7,12,9,5,6,5,4,7,3,5,4,2,3,0,1\n", + "0,0,0,0,1,3,1,6,6,5,5,6,3,6,13,3,10,13,9,16,15,9,11,4,6,4,11,11,12,3,5,8,7,4,6,4,1,3,0,0\n", + "0,1,2,1,1,1,4,1,5,2,3,3,10,7,13,5,7,17,6,9,12,13,10,4,12,4,6,7,6,10,8,2,5,1,3,4,2,0,2,0\n", + "0,1,1,0,1,2,4,3,6,4,7,5,5,7,5,10,7,8,18,17,9,8,12,11,11,11,14,6,11,2,10,9,5,6,5,3,4,2,2,0\n", + "0,0,0,0,2,3,6,5,7,4,3,2,10,7,9,11,12,5,12,9,13,19,14,17,5,13,8,11,5,10,9,8,7,5,3,1,4,0,2,1\n", + "0,0,0,1,2,1,4,3,6,7,4,2,12,6,12,4,14,7,8,14,13,19,6,9,12,6,4,13,6,7,2,3,6,5,4,2,3,0,1,0\n", + "0,0,2,1,2,5,4,2,7,8,4,7,11,9,8,11,15,17,11,12,7,12,7,6,7,4,13,5,7,6,6,9,2,1,1,2,2,0,1,0\n", + "0,1,2,0,1,4,3,2,2,7,3,3,12,13,11,13,6,5,9,16,9,19,16,11,8,9,14,12,11,9,6,6,6,1,1,2,4,3,1,1\n", + "0,1,1,3,1,4,4,1,8,2,2,3,12,12,10,15,13,6,5,5,18,19,9,6,11,12,7,6,3,6,3,2,4,3,1,5,4,2,2,0\n", + "0,0,2,3,2,3,2,6,3,8,7,4,6,6,9,5,12,12,8,5,12,10,16,7,14,12,5,4,6,9,8,5,6,6,1,4,3,0,2,0\n", + "0,0,0,3,4,5,1,7,7,8,2,5,12,4,10,14,5,5,17,13,16,15,13,6,12,9,10,3,3,7,4,4,8,2,6,5,1,0,1,0\n", + "0,1,1,1,1,3,3,2,6,3,9,7,8,8,4,13,7,14,11,15,14,13,5,13,7,14,9,10,5,11,5,3,5,1,1,4,4,1,2,0\n", + "0,1,1,1,2,3,5,3,6,3,7,10,3,8,12,4,12,9,15,5,17,16,5,10,10,15,7,5,3,11,5,5,6,1,1,1,1,0,2,1\n", + "0,0,2,1,3,3,2,7,4,4,3,8,12,9,12,9,5,16,8,17,7,11,14,7,13,11,7,12,12,7,8,5,7,2,2,4,1,1,1,0\n", + "0,0,1,2,4,2,2,3,5,7,10,5,5,12,3,13,4,13,7,15,9,12,18,14,16,12,3,11,3,2,7,4,8,2,2,1,3,0,1,1\n", + "0,0,1,1,1,5,1,5,2,2,4,10,4,8,14,6,15,6,12,15,15,13,7,17,4,5,11,4,8,7,9,4,5,3,2,5,4,3,2,1\n", + "0,0,2,2,3,4,6,3,7,6,4,5,8,4,7,7,6,11,12,19,20,18,9,5,4,7,14,8,4,3,7,7,8,3,5,4,1,3,1,0\n", + "0,0,0,1,4,4,6,3,8,6,4,10,12,3,3,6,8,7,17,16,14,15,17,4,14,13,4,4,12,11,6,9,5,5,2,5,2,1,0,1\n", + "0,1,1,0,3,2,4,6,8,6,2,3,11,3,14,14,12,8,8,16,13,7,6,9,15,7,6,4,10,8,10,4,2,6,5,5,2,3,2,1\n", + "0,0,2,3,3,4,5,3,6,7,10,5,10,13,14,3,8,10,9,9,19,15,15,6,8,8,11,5,5,7,3,6,6,4,5,2,2,3,0,0\n", + "0,1,2,2,2,3,6,6,6,7,6,3,11,12,13,15,15,10,14,11,11,8,6,12,10,5,12,7,7,11,5,8,5,2,5,5,2,0,2,1\n", + "0,0,2,1,3,5,6,7,5,8,9,3,12,10,12,4,12,9,13,10,10,6,10,11,4,15,13,7,3,4,2,9,7,2,4,2,1,2,1,1\n", + "0,0,1,2,4,1,5,5,2,3,4,8,8,12,5,15,9,17,7,19,14,18,12,17,14,4,13,13,8,11,5,6,6,2,3,5,2,1,1,1\n", + "0,0,0,3,1,3,6,4,3,4,8,3,4,8,3,11,5,7,10,5,15,9,16,17,16,3,8,9,8,3,3,9,5,1,6,5,4,2,2,0\n", + "0,1,2,2,2,5,5,1,4,6,3,6,5,9,6,7,4,7,16,7,16,13,9,16,12,6,7,9,10,3,6,4,5,4,6,3,4,3,2,1\n", + "0,1,1,2,3,1,5,1,2,2,5,7,6,6,5,10,6,7,17,13,15,16,17,14,4,4,10,10,10,11,9,9,5,4,4,2,1,0,1,0\n", + "0,1,0,3,2,4,1,1,5,9,10,7,12,10,9,15,12,13,13,6,19,9,10,6,13,5,13,6,7,2,5,5,2,1,1,1,1,3,0,1\n", + "0,1,1,3,1,1,5,5,3,7,2,2,3,12,4,6,8,15,16,16,15,4,14,5,13,10,7,10,6,3,2,3,6,3,3,5,4,3,2,1\n", + "0,0,0,2,2,1,3,4,5,5,6,5,5,12,13,5,7,5,11,15,18,7,9,10,14,12,11,9,10,3,2,9,6,2,2,5,3,0,0,1\n", + "0,0,1,3,3,1,2,1,8,9,2,8,10,3,8,6,10,13,11,17,19,6,4,11,6,12,7,5,5,4,4,8,2,6,6,4,2,2,0,0\n", + "0,1,1,3,4,5,2,1,3,7,9,6,10,5,8,15,11,12,15,6,12,16,6,4,14,3,12,9,6,11,5,8,5,5,6,1,2,1,2,0\n", + "0,0,1,3,1,4,3,6,7,8,5,7,11,3,6,11,6,10,6,19,18,14,6,10,7,9,8,5,8,3,10,2,5,1,5,4,2,1,0,1\n", + "0,1,1,3,3,4,4,6,3,4,9,9,7,6,8,15,12,15,6,11,6,18,5,14,15,12,9,8,3,6,10,6,8,7,2,5,4,3,1,1\n", + "0,1,2,2,4,3,1,4,8,9,5,10,10,3,4,6,7,11,16,6,14,9,11,10,10,7,10,8,8,4,5,8,4,4,5,2,4,1,1,0\n", + "0,0,2,3,4,5,4,6,2,9,7,4,9,10,8,11,16,12,15,17,19,10,18,13,15,11,8,4,7,11,6,7,6,5,1,3,1,0,0,0\n", + "0,1,1,3,1,4,6,2,8,2,10,3,11,9,13,15,5,15,6,10,10,5,14,15,12,7,4,5,11,4,6,9,5,6,1,1,2,1,2,1\n", + "0,0,1,3,2,5,1,2,7,6,6,3,12,9,4,14,4,6,12,9,12,7,11,7,16,8,13,6,7,6,10,7,6,3,1,5,4,3,0,0\n", + "0,0,1,2,3,4,5,7,5,4,10,5,12,12,5,4,7,9,18,16,16,10,15,15,10,4,3,7,5,9,4,6,2,4,1,4,2,2,2,1\n", + "0,1,2,1,1,3,5,3,6,3,10,10,11,10,13,10,13,6,6,14,5,4,5,5,9,4,12,7,7,4,7,9,3,3,6,3,4,1,2,0\n", + "0,1,2,2,3,5,2,4,5,6,8,3,5,4,3,15,15,12,16,7,20,15,12,8,9,6,12,5,8,3,8,5,4,1,3,2,1,3,1,0\n", + "0,0,0,2,4,4,5,3,3,3,10,4,4,4,14,11,15,13,10,14,11,17,9,11,11,7,10,12,10,10,10,8,7,5,2,2,4,1,2,1\n", + "0,0,2,1,1,4,4,7,2,9,4,10,12,7,6,6,11,12,9,15,15,6,6,13,5,12,9,6,4,7,7,6,5,4,1,4,2,2,2,1\n", + "0,1,2,1,1,4,5,4,4,5,9,7,10,3,13,13,8,9,17,16,16,15,12,13,5,12,10,9,11,9,4,5,5,2,2,5,1,0,0,1\n", + "0,0,1,3,2,3,6,4,5,7,2,4,11,11,3,8,8,16,5,13,16,5,8,8,6,9,10,10,9,3,3,5,3,5,4,5,3,3,0,1\n", + "0,1,1,2,2,5,1,7,4,2,5,5,4,6,6,4,16,11,14,16,14,14,8,17,4,14,13,7,6,3,7,7,5,6,3,4,2,2,1,1\n", + "0,1,1,1,4,1,6,4,6,3,6,5,6,4,14,13,13,9,12,19,9,10,15,10,9,10,10,7,5,6,8,6,6,4,3,5,2,1,1,1\n", + "0,0,0,1,4,5,6,3,8,7,9,10,8,6,5,12,15,5,10,5,8,13,18,17,14,9,13,4,10,11,10,8,8,6,5,5,2,0,2,0\n", + "0,0,1,0,3,2,5,4,8,2,9,3,3,10,12,9,14,11,13,8,6,18,11,9,13,11,8,5,5,2,8,5,3,5,4,1,3,1,1,0\n" + ] + } + ], "source": [ - "with open(all_paths[0], 'r') as f:\n", - " # YOUR CODE HERE: Use the readline() method to read the .csv file into 'contents'\n", - " \n", + "\n", + "# List of file paths\n", + "all_paths = [\n", + " \"../05_data/assignment_2_data/inflammation_01.csv\",\n", + " \"../05_data/assignment_2_data/inflammation_02.csv\",\n", + " \"../05_data/assignment_2_data/inflammation_03.csv\",\n", + " \"../05_data/assignment_2_data/inflammation_04.csv\",\n", + " \"../05_data/assignment_2_data/inflammation_05.csv\",\n", + " \"../05_data/assignment_2_data/inflammation_06.csv\",\n", + " \"../05_data/assignment_2_data/inflammation_07.csv\",\n", + " \"../05_data/assignment_2_data/inflammation_08.csv\",\n", + " \"../05_data/assignment_2_data/inflammation_09.csv\",\n", + " \"../05_data/assignment_2_data/inflammation_10.csv\",\n", + " \"../05_data/assignment_2_data/inflammation_11.csv\",\n", + " \"../05_data/assignment_2_data/inflammation_12.csv\",\n", + "]\n", + "\n", + " #with open(all_paths[0], 'r') as f:\n", + " # YOUR CODE HERE: Use the readlines() method to read the .csv file into 'contents'\n", + "\n", + " # Iterate through all files\n", + "for file_path in all_paths:\n", + " with open(file_path, 'r') as f:\n", + " # Read the contents of the file into 'contents'\n", + " contents = f.readlines()\n", + " # Display the contents of the first file\n", + " print(f\"Contents of {file_path}:\")\n", + " for line in contents:\n", + " print(line.strip()) # Strip removes leading/trailing whitespace and newline characters\n", + " # Break out of the loop after displaying the contents of the first file\n", + " break\n", + "\n", " # YOUR CODE HERE: Iterate through 'contents' using a for loop and print each row for inspection" ] }, @@ -133,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "id": "82-bk4CBB1w4" }, @@ -142,22 +239,25 @@ "import numpy as np\n", "\n", "def patient_summary(file_path, operation):\n", - " # load the data from the file\n", + " # Load the data from the file\n", " data = np.loadtxt(fname=file_path, delimiter=',')\n", - " ax = 1 # this specifies that the operation should be done for each row (patient)\n", + " ax = 1 # This specifies that the operation should be done for each row (patient)\n", "\n", - " # implement the specific operation based on the 'operation' argument\n", + " # Implement the specific operation based on the 'operation' argument\n", " if operation == 'mean':\n", - " # YOUR CODE HERE: calculate the mean (average) number of flare-ups for each patient\n", + " # Calculate the mean (average) number of flare-ups for each patient\n", + " summary_values = np.mean(data, axis=ax)\n", "\n", " elif operation == 'max':\n", - " # YOUR CODE HERE: calculate the maximum number of flare-ups experienced by each patient\n", + " # Calculate the maximum number of flare-ups experienced by each patient\n", + " summary_values = np.max(data, axis=ax)\n", "\n", " elif operation == 'min':\n", - " # YOUR CODE HERE: calculate the minimum number of flare-ups experienced by each patient\n", + " # Calculate the minimum number of flare-ups experienced by each patient\n", + " summary_values = np.min(data, axis=ax)\n", "\n", " else:\n", - " # if the operation is not one of the expected values, raise an error\n", + " # If the operation is not one of the expected values, raise an error\n", " raise ValueError(\"Invalid operation. Please choose 'mean', 'max', or 'min'.\")\n", "\n", " return summary_values" @@ -165,11 +265,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "id": "3TYo0-1SDLrd" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60\n" + ] + } + ], "source": [ "# test it out on the data file we read in and make sure the size is what we expect i.e., 60\n", "# Your output for the first file should be 60\n", @@ -232,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "id": "_svDiRkdIwiT" }, @@ -255,25 +363,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { "id": "LEYPM5v4JT0i" }, "outputs": [], "source": [ "# Define your function `detect_problems` here\n", - "\n", "def detect_problems(file_path):\n", - " #YOUR CODE HERE: use patient_summary() to get the means and check_zeros() to check for zeros in the means\n", + " # Use patient_summary() to get the means\n", + " means = patient_summary(file_path, 'mean')\n", "\n", - " return" + " # Check for zeros in the means using the helper function check_zeros()\n", + " if check_zeros(means):\n", + " return True\n", + " else:\n", + " return False\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], "source": [ "# Test out your code here\n", "# Your output for the first file should be True\n", @@ -331,7 +451,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.15" } }, "nbformat": 4,