From 0ab3d6655f2fea8bf05f3ec195d2deed79e8fccf Mon Sep 17 00:00:00 2001 From: Michael Howorucha Date: Thu, 12 Mar 2026 12:05:44 -0600 Subject: [PATCH 1/2] created anagram_checker functions to compare two words and determine if they are anagrams. --- 02_activities/assignments/assignment_1.ipynb | 119 ++++++++++++++++--- 1 file changed, 104 insertions(+), 15 deletions(-) diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index 2dca19d0b..fa8db03af 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,13 +56,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "import numpy as np\n", + "\n", "# For testing purposes, we will write our code in the function\n", "def anagram_checker(word_a, word_b):\n", - " # Your code here\n", + " # find the unique characters in each word and their counts\n", + " chars1, counts = np.unique(np.array(list(word_a.lower()), dtype='U1'), return_counts=True)\n", + " chars2, counts2 = np.unique(np.array(list(word_b.lower()), dtype='U1'), return_counts=True)\n", + " # create dictionaries of the characters and their counts for each word\n", + " dict1 = dict(zip(chars1, counts))\n", + " dict2 = dict(zip(chars2, counts2))\n", + " # return whether the two dictionaries are equal (i.e. the words are anagrams)\n", + " return dict1 == dict2\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -70,18 +90,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Night\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"night\", \"Thing\")" ] @@ -99,10 +141,35 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "#import numpy as np\n", + "\n", "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", + " # is we are not considering case sensitivity, convert both words to lowercase\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + "\n", + " # find the unique characters in each word and their counts\n", + " chars1, counts = np.unique(np.array(list(word_a), dtype='U1'), return_counts=True)\n", + " chars2, counts2 = np.unique(np.array(list(word_b), dtype='U1'), return_counts=True)\n", + " # create dictionaries of the characters and their counts for each word\n", + " dict1 = dict(zip(chars1, counts))\n", + " dict2 = dict(zip(chars2, counts2))\n", + " # return whether the two dictionaries are equal (i.e. the words are anagrams)\n", + " return dict1 == dict2\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\", False) # True" @@ -110,18 +177,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"listen\", True) # False" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Listen\", True) # False" ] @@ -139,7 +228,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -153,7 +242,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.12.3" } }, "nbformat": 4, From 33cd798646835ee2caa5b24741f5a1b797336ac6 Mon Sep 17 00:00:00 2001 From: Michael Howorucha Date: Thu, 19 Mar 2026 11:41:15 -0400 Subject: [PATCH 2/2] Created Functions to Analyze Patient Data --- 02_activities/assignments/assignment_2.ipynb | 201 ++++++++++++++++--- 1 file changed, 178 insertions(+), 23 deletions(-) diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index 1ae6fe242..f16fd1640 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -76,7 +76,134 @@ "metadata": { "id": "n0m48JsS-nMC" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,0,0,2,0,4,1,7,2,6,4,7,2,4,10,7,3,13,9,3,0,1,0,15,0,5,12,3,8,6,8,6,4,3,3,2,0,0,0,0\n", + "\n", + "0,0,0,3,0,4,3,5,3,11,4,13,6,2,8,1,3,0,17,12,4,3,4,4,9,8,8,2,5,3,11,2,3,1,5,0,1,1,0,0\n", + "\n", + "0,0,1,2,0,1,0,1,6,9,4,3,7,5,4,14,8,5,0,10,5,4,9,12,4,5,5,8,6,2,0,0,1,7,6,1,1,0,0,0\n", + "\n", + "0,0,0,0,0,3,7,3,2,1,5,2,8,0,10,3,3,1,13,11,12,0,5,0,5,6,10,8,4,3,2,11,3,5,1,1,0,0,0,0\n", + "\n", + "0,0,1,0,0,2,1,2,3,9,6,14,4,6,13,8,7,13,0,15,3,1,3,1,6,4,4,0,4,2,5,11,3,5,6,0,0,1,0,0\n", + "\n", + "0,0,0,1,1,2,2,7,4,5,4,6,5,3,11,6,2,14,1,15,8,3,3,1,2,0,8,3,14,5,4,1,2,4,6,3,1,1,0,0\n", + "\n", + "0,0,1,2,1,0,0,1,1,5,2,14,9,1,12,12,1,13,10,14,2,13,4,16,8,0,12,2,3,4,7,6,3,2,1,0,0,0,0,0\n", + "\n", + "0,0,0,2,0,5,2,5,1,5,6,11,2,4,2,5,0,0,4,1,7,1,7,17,12,5,5,4,3,6,1,0,5,5,0,2,3,0,0,0\n", + "\n", + "0,0,0,2,0,2,6,3,1,6,3,9,8,4,11,5,0,10,9,3,9,5,5,16,10,2,2,8,10,1,1,0,0,2,2,1,3,0,0,0\n", + "\n", + "0,0,0,2,0,3,3,5,6,0,0,12,7,0,16,8,2,19,0,7,2,13,5,8,11,2,5,5,1,5,7,11,5,3,3,3,2,0,0,0\n", + "\n", + "0,0,0,1,1,5,3,7,5,8,5,10,4,4,13,8,8,6,14,14,8,9,3,1,0,1,6,4,10,4,5,2,1,1,6,0,0,0,0,0\n", + "\n", + "0,0,0,0,1,4,4,4,1,3,2,10,3,5,10,14,6,11,2,8,10,12,2,3,10,4,0,8,14,1,1,6,1,5,1,2,1,0,0,0\n", + "\n", + "0,0,1,3,0,2,5,1,5,1,3,8,5,6,7,6,7,14,4,15,0,2,3,0,2,8,16,1,13,0,3,5,0,4,1,2,0,1,0,0\n", + "\n", + "0,0,0,2,0,4,5,7,6,11,4,14,2,1,14,8,4,5,8,2,8,11,6,9,10,3,14,8,10,2,11,4,1,1,1,0,0,1,0,0\n", + "\n", + "0,0,0,0,0,5,4,1,6,0,3,7,7,5,11,8,1,7,2,13,12,5,6,10,16,2,12,3,3,6,10,1,2,3,4,3,2,0,0,0\n", + "\n", + "0,0,1,0,1,1,1,6,2,5,6,2,1,1,4,6,0,10,12,15,6,1,5,0,8,3,1,4,4,6,3,2,2,5,4,0,1,0,0,0\n", + "\n", + "0,0,1,1,1,0,2,0,1,8,6,5,3,1,2,12,5,12,2,14,9,8,4,1,14,1,11,7,10,1,5,6,4,7,6,3,2,1,0,0\n", + "\n", + "0,0,1,0,1,0,7,2,0,6,4,7,9,0,12,5,2,18,5,15,6,5,0,4,16,7,2,6,2,5,11,7,1,0,1,3,1,0,0,0\n", + "\n", + "0,0,1,2,0,1,4,6,1,12,6,9,0,2,8,3,6,0,7,12,5,15,10,5,16,7,1,4,11,6,6,5,2,4,1,1,1,0,0,0\n", + "\n", + "0,0,1,3,0,0,2,3,0,4,2,9,7,1,11,11,8,0,16,0,4,7,10,14,0,7,15,1,11,4,1,0,2,4,2,3,1,1,0,0\n", + "\n", + "0,0,1,2,1,3,0,3,6,4,4,5,9,3,14,7,4,20,6,0,6,7,7,5,8,7,13,8,3,4,9,10,3,2,0,0,3,1,0,0\n", + "\n", + "0,0,0,0,0,3,5,4,1,5,3,14,7,6,15,15,7,20,16,11,10,17,5,16,2,3,9,8,14,0,7,3,5,1,2,0,1,1,0,0\n", + "\n", + "0,0,1,0,1,0,3,5,6,1,3,13,6,2,16,0,8,11,7,1,10,12,0,1,12,6,6,4,12,3,0,0,1,1,3,1,3,0,0,0\n", + "\n", + "0,0,1,2,1,5,7,5,3,9,5,12,1,4,1,15,1,5,8,9,5,1,7,3,7,2,12,7,11,2,5,0,0,0,1,0,3,0,0,0\n", + "\n", + "0,0,0,3,0,0,6,3,5,1,6,14,6,0,4,2,9,13,12,13,8,6,4,15,8,5,16,7,13,3,11,3,4,1,5,3,1,1,0,0\n", + "\n", + "0,0,1,2,0,2,1,6,1,7,1,1,5,6,15,1,4,10,12,8,0,6,2,1,9,4,10,7,6,6,11,2,5,5,5,0,1,0,0,0\n", + "\n", + "0,0,0,3,1,1,4,1,0,4,4,5,1,6,14,16,4,10,12,8,10,1,0,19,3,2,9,7,3,5,8,5,4,6,0,3,0,0,0,0\n", + "\n", + "0,0,1,3,0,3,1,5,1,10,3,5,2,1,0,6,2,9,0,3,12,5,3,5,16,2,9,1,13,5,11,1,1,5,1,2,0,1,0,0\n", + "\n", + "0,0,0,1,1,3,2,1,4,4,3,7,3,6,1,17,4,11,0,13,6,8,8,2,3,5,0,7,14,1,4,7,0,0,1,1,3,0,0,0\n", + "\n", + "0,0,0,3,0,3,1,0,4,0,3,1,1,6,5,5,7,18,9,9,2,15,8,1,9,7,8,3,5,5,2,4,0,1,0,1,1,1,0,0\n", + "\n", + "0,0,1,0,0,5,0,3,2,8,1,6,4,6,15,9,6,15,11,6,3,11,3,13,7,0,7,0,5,0,5,1,1,0,1,0,2,0,0,0\n", + "\n", + "0,0,0,2,0,1,1,7,2,4,0,8,6,0,1,12,3,5,15,0,12,13,9,7,15,5,16,5,13,5,3,0,0,3,4,0,3,1,0,0\n", + "\n", + "0,0,0,0,1,5,3,0,1,4,0,12,1,5,13,3,8,20,15,4,2,14,1,6,3,8,3,8,7,3,0,9,1,0,1,1,3,0,0,0\n", + "\n", + "0,0,0,2,1,3,1,5,2,11,1,2,4,2,4,5,1,7,2,14,5,16,3,16,6,2,15,1,8,2,4,3,4,4,3,1,1,0,0,0\n", + "\n", + "0,0,0,0,1,0,7,7,2,7,5,10,2,1,17,10,4,8,16,4,9,3,3,8,5,7,6,0,4,1,1,3,0,6,2,1,3,1,0,0\n", + "\n", + "0,0,0,2,0,1,1,5,5,8,6,8,9,1,7,9,2,3,11,5,10,9,0,15,14,4,14,7,8,1,4,7,1,0,6,1,3,0,0,0\n", + "\n", + "0,0,1,0,0,1,4,4,5,5,0,8,6,1,17,16,7,20,7,13,5,16,9,6,10,7,4,5,3,5,0,5,2,1,5,0,2,1,0,0\n", + "\n", + "0,0,1,2,1,1,2,5,3,9,1,5,0,4,2,14,7,6,16,16,6,2,5,13,10,8,8,8,6,5,5,10,1,7,6,1,0,0,0,0\n", + "\n", + "0,0,1,2,0,0,4,1,0,11,3,0,1,0,14,13,4,16,12,0,10,12,0,18,16,2,10,3,5,5,4,8,5,1,3,3,0,1,0,0\n", + "\n", + "0,0,0,3,0,5,2,4,3,8,6,9,4,5,10,4,6,17,13,10,5,11,5,18,8,1,4,3,13,0,2,5,0,0,3,1,1,1,0,0\n", + "\n", + "0,0,1,3,1,4,7,5,5,8,1,3,2,6,8,1,8,3,17,16,1,10,1,9,3,6,1,1,8,0,0,3,5,4,3,2,2,1,0,0\n", + "\n", + "0,0,1,0,1,3,4,2,1,0,6,14,2,6,13,6,1,18,15,11,9,17,8,15,2,1,9,5,5,4,1,11,3,7,6,3,2,1,0,0\n", + "\n", + "0,0,1,0,0,5,7,4,1,6,3,2,5,0,16,11,2,6,16,0,7,4,5,7,13,4,2,8,9,2,0,2,1,2,3,3,0,0,0,0\n", + "\n", + "0,0,0,1,0,5,4,6,1,7,5,14,4,0,12,3,3,13,2,8,11,13,0,0,10,0,15,0,13,1,10,3,0,1,5,3,2,1,0,0\n", + "\n", + "0,0,1,3,0,0,1,4,5,6,2,9,6,3,3,2,7,19,6,1,12,9,8,18,11,4,7,6,5,1,1,4,4,2,1,2,1,0,0,0\n", + "\n", + "0,0,1,3,0,5,7,5,4,11,3,0,3,1,10,2,5,8,12,7,11,7,2,9,15,7,7,0,14,4,0,6,4,6,4,1,2,0,0,0\n", + "\n", + "0,0,1,3,0,4,5,3,5,1,3,10,4,2,2,16,6,1,12,1,11,5,2,5,14,2,2,3,10,6,0,3,5,7,6,0,3,1,0,0\n", + "\n", + "0,0,1,1,1,0,2,2,3,2,4,4,6,4,6,13,6,11,15,2,10,3,3,2,6,8,7,5,13,3,0,7,3,2,2,0,2,1,0,0\n", + "\n", + "0,0,1,3,0,3,0,3,6,3,5,9,3,3,10,3,9,1,9,6,12,13,8,11,16,4,2,3,1,5,1,9,4,0,5,3,2,0,0,0\n", + "\n", + "0,0,1,1,0,1,6,2,5,8,0,7,2,5,13,14,0,19,4,16,9,2,6,16,3,3,6,0,11,0,1,9,2,2,5,1,2,1,0,0\n", + "\n", + "0,0,1,1,0,3,4,4,5,5,0,6,7,3,14,9,8,7,6,1,0,13,9,3,1,2,5,0,12,5,5,0,5,7,3,1,0,1,0,0\n", + "\n", + "0,0,1,0,1,2,2,1,5,0,6,8,8,5,3,13,3,6,6,15,7,12,2,19,16,8,10,0,7,1,3,6,3,2,4,1,0,0,0,0\n", + "\n", + "0,0,1,2,1,3,6,5,0,7,5,7,2,1,11,1,5,4,1,2,6,7,7,7,13,4,2,2,9,1,12,0,4,6,1,0,3,1,0,0\n", + "\n", + "0,0,1,1,1,3,0,4,3,8,0,1,1,4,2,6,6,6,7,13,12,15,3,12,13,8,11,1,8,2,0,1,2,0,0,2,2,1,0,0\n", + "\n", + "0,0,0,0,0,3,6,3,3,3,0,11,8,6,4,0,3,17,8,2,8,5,3,18,5,8,1,6,0,6,12,1,3,6,0,1,0,0,0,0\n", + "\n", + "0,0,1,3,0,2,6,5,6,7,2,10,1,4,14,11,1,19,14,8,10,14,10,4,11,8,8,2,3,5,2,2,3,6,5,0,1,0,0,0\n", + "\n", + "0,0,1,2,1,2,4,5,3,10,5,10,0,4,12,8,2,12,8,8,4,14,1,13,2,8,6,5,1,4,3,2,3,6,1,2,1,0,0,0\n", + "\n", + "0,0,1,3,0,3,2,0,3,2,6,11,3,1,0,3,3,0,11,1,6,3,4,16,3,2,13,6,9,4,1,7,5,3,3,1,3,1,0,0\n", + "\n", + "0,0,1,2,1,0,4,3,1,6,4,14,4,3,14,17,1,0,8,5,4,4,10,2,14,5,11,0,6,4,4,5,0,3,0,0,2,1,0,0\n", + "\n", + "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", + "\n" + ] + } + ], "source": [ "all_paths = [\n", " \"../../05_src/data/assignment_2_data/inflammation_01.csv\",\n", @@ -93,10 +220,13 @@ " \"../../05_src/data/assignment_2_data/inflammation_12.csv\"\n", "]\n", "\n", - "with open(all_paths[0], 'r') as f:\n", - " # YOUR CODE HERE: Use the readline() or readlines() method to read the .csv file into a variable\n", - " \n", - " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection" + "with open(all_paths[2], 'r') as f:\n", + " # read all lines in the given file \n", + " lines = f.readlines() \n", + " # print out each line in the file, line by line\n", + " for line in lines:\n", + " print(line)\n", + " " ] }, { @@ -144,33 +274,46 @@ "\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", - "\n", + " # Calculate the mean of the data along the \"ax\" axis\n", + " result = np.mean(data, axis=ax)\n", " elif operation == 'max':\n", - " # YOUR CODE HERE: Calculate the maximum number of flare-ups experienced by each patient\n", - "\n", + " # Find the maximum value in the data along the \"ax\" axis\n", + " result = np.max(data, axis=ax)\n", " elif operation == 'min':\n", - " # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\n", + " # Find the minimum value in the data along the \"ax\" axis\n", + " result = np.min(data, axis=ax)\n", "\n", " else:\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" + " return result" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "id": "3TYo0-1SDLrd" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60\n", + "[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", + " 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", + " 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\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", - "data_min = patient_summary(all_paths[0], 'min')\n", - "print(len(data_min))" + "data_min = patient_summary(all_paths[2], 'min')\n", + "print(len(data_min))\n", + "print(data_min)" ] }, { @@ -228,7 +371,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "_svDiRkdIwiT" }, @@ -260,20 +403,31 @@ "# 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 calculate the mean flare-ups for each patient at one check-in\n", + " means = patient_summary(file_path, 'mean')\n", + " # use check_zeros to check if any of the means are zero, if so return True, if not return Flase\n", + " has_zeros = check_zeros(means)\n", "\n", - " return" + " return has_zeros" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ "# Test out your code here\n", "# Your output for the first file should be False\n", - "print(detect_problems(all_paths[0]))" + "print(detect_problems(all_paths[2]))" ] }, { @@ -314,7 +468,8 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "python-env (3.11.14)", + "language": "python", "name": "python3" }, "language_info": { @@ -327,7 +482,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.14" } }, "nbformat": 4,