From 6c8cba888e7b852a621e053b59535b9e4d0b7192 Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Wed, 7 Jan 2026 02:22:54 -0800 Subject: [PATCH 01/17] initial commit --- AD450_math.py | 5 + week_2_intro_ipython.ipynb | 403 ++++++++++++++++++++++++++++++++----- 2 files changed, 354 insertions(+), 54 deletions(-) create mode 100644 AD450_math.py diff --git a/AD450_math.py b/AD450_math.py new file mode 100644 index 0000000..911df99 --- /dev/null +++ b/AD450_math.py @@ -0,0 +1,5 @@ +def add(num1, num2): + return num1 + num2 + +def multiply(num1, num2): + return num1 * num2 \ No newline at end of file diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index 1a469f7..bb7ba0e 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -24,12 +24,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "id": "BQybla17FRh5" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My name is Joe.\n", + "I am a student at North Seattle College.\n" + ] + } + ], + "source": [ + "name = \"Joe\"\n", + "\n", + "print(f\"My name is {name}.\")\n", + "print(\"I am a student at North Seattle College.\")" + ] }, { "cell_type": "markdown", @@ -43,12 +57,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "P7QDyWncFRh8" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My phone numberis 206-555-5555\n" + ] + } + ], + "source": [ + "phone_num = \"206-555-5555\"\n", + "\n", + "print(f\"My phone numberis {phone_num}\")" + ] }, { "cell_type": "markdown", @@ -62,12 +88,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "id": "OnOau948FRh9" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello my name is Joe and my phone number is 206-555-5555\n" + ] + } + ], + "source": [ + "print(f\"Hello my name is {name} and my phone number is {phone_num}\")" + ] }, { "cell_type": "markdown", @@ -82,12 +118,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "id": "5x2rIFzRFRh9" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I graduate in June of 2027.\n" + ] + } + ], + "source": [ + "month = \"June\"\n", + "year = 2027 \n", + "\n", + "print(f\"I graduate in {month} of {year}.\")" + ] }, { "cell_type": "markdown", @@ -109,12 +158,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "OkyeAVPXFRh-" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ans = 58.5\n" + ] + } + ], + "source": [ + "ans = 12 * 5 - 3 / 2\n", + "ans_type = str(type(ans))\n", + "\n", + "print(f\"ans = {ans}\")\n", + "\n", + "# ans is a float" + ] }, { "cell_type": "markdown", @@ -136,12 +200,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "Lo-LEy8bKYmG" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "31 days\n" + ] + } + ], + "source": [ + "oct = \"October\"\n", + "\n", + "if oct == \"October\":\n", + " print(\"31 days\")\n", + "else:\n", + " print(\"30 days\")" + ] }, { "cell_type": "markdown", @@ -157,12 +236,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "id": "qscUkh813QKH" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "between 100 and 150\n" + ] + } + ], + "source": [ + "x = 140\n", + "\n", + "if x > 150:\n", + " print(\"greater than 150\")\n", + "elif x > 100 and x < 150:\n", + " print(\"between 100 and 150\")\n", + "else:\n", + " print(\"less than 100\")" + ] }, { "cell_type": "markdown", @@ -177,12 +273,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "1vxg4nMbFRh_" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number is divisible by 5 and 10.\n", + "Number is divisible by 7 or by 2\n" + ] + } + ], + "source": [ + "y = 70\n", + "\n", + "if y % 5 == 0 and y % 10 == 0:\n", + " print(\"Number is divisible by 5 and 10.\")\n", + "\n", + "if y % 7 == 0 or y % 2 == 0:\n", + " print(\"Number is divisible by 7 or by 2\")\n" + ] }, { "cell_type": "markdown", @@ -195,12 +308,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "JY_Ci5v-FRiA" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "7\n", + "14\n", + "21\n", + "28\n", + "35\n", + "42\n", + "49\n", + "56\n", + "63\n", + "70\n", + "77\n", + "84\n", + "91\n", + "98\n" + ] + } + ], + "source": [ + "for i in range(1,101):\n", + " if i % 7 == 0:\n", + " print(i)" + ] }, { "cell_type": "markdown", @@ -213,12 +351,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "4a1D64hpFRiA" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "6\n", + "9\n" + ] + } + ], + "source": [ + "for i in range(1,11):\n", + " if i % 3 == 0:\n", + " print(i)" + ] }, { "cell_type": "markdown", @@ -241,12 +393,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "id": "ntBnYxzi1RPc" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Set: 1\n", + "Set: 2\n", + "Student: 1\n", + "Student: 2\n", + "Student: 3\n", + "Student: 4\n", + "Student: 5\n", + "Set: 3\n", + "Set: 4\n", + "Student: 1\n", + "Student: 2\n", + "Student: 3\n", + "Student: 4\n", + "Student: 5\n", + "Set: 5\n" + ] + } + ], + "source": [ + "for i in range(1,6):\n", + " print(f\"Set: {i}\")\n", + " if i % 2 == 0:\n", + " for j in range(1,6):\n", + " print(f\"Student: {j}\")" + ] }, { "cell_type": "markdown", @@ -259,12 +439,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "lppms8ctzfRI" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hog\n", + "warts\n", + "s\n" + ] + } + ], + "source": [ + "school = \"Hogwarts\"\n", + "first = school[:3]\n", + "second = school[3:]\n", + "\n", + "print(first)\n", + "print(second)\n", + "print(school[-1])" + ] }, { "cell_type": "markdown", @@ -280,12 +478,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "id": "zw2NezoM0zfl" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Thor is a character in the Marvel Cinematic Universe. She-Hulk is a character in the Marvel Cinematic Universe. Loki is a character in the Marvel Cinematic Universe. \n" + ] + } + ], + "source": [ + "chars = [\"Thor\", \"She-Hulk\", \"Loki\"]\n", + "output = \"\"\n", + "\n", + "for i in range(len(chars)):\n", + " output += chars[i]\n", + " output += \" is a character in the Marvel Cinematic Universe. \"\n", + "\n", + "print(output)" + ] }, { "cell_type": "markdown", @@ -299,12 +514,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "id": "rbyZif9a1b2V" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "January has 31 days. \n", + "February has 28 days. \n", + "March has 31 days. \n", + "April has 30 days. \n", + "May has 31 days. \n", + "June has 30 days. \n" + ] + } + ], + "source": [ + "months = [[\"January\", 31], [\"February\", 28], [\"March\", 31], [\"April\", 30], [\"May\", 31], [\"June\", 30]]\n", + "\n", + "for i in range(len(months)):\n", + " print(f\"{months[i][0]} has {months[i][1]} days. \")" + ] }, { "cell_type": "markdown", @@ -321,12 +554,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": { "id": "p0YE0nqs4Hcz" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'breed': 'Corgi', 'Age Exp.': 13, 'Type': 'Cattle herding'}\n", + "Corgi\n", + "The Corgi is expected to live about 13 years.\n" + ] + } + ], + "source": [ + "dog = {\"breed\": \"Corgi\", \"Age Exp.\": 13, \"Type\": \"Cattle herding\"}\n", + "\n", + "print(dog)\n", + "\n", + "print(dog[\"breed\"])\n", + "\n", + "print(f\"The {dog['breed']} is expected to live about {dog['Age Exp.']} years.\")\n", + "\n", + "# I used AI to help me with this as I kept getting an error on the last print statement \n", + "# because I was using double quotes for the variable I was placing inside the f-string. \n", + "# I was trying to access it like this dog[\"breed\"] but kept getting an error. So I pasted \n", + "# it into gpt and it explained that the interpreter was interpreting the first double \n", + "# quotation mark as the end of the f-string. Thus causing the error.\n", + "\n", + "# I also learned that in juypter you can't use multi-line comments in juypter notebooks \n", + "# by using the triple quotes before and after a comment\n" + ] }, { "cell_type": "markdown", @@ -337,9 +597,20 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import AD450_math\n", "\n", @@ -359,9 +630,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "AttributeError", + "evalue": "module 'AD450_math' has no attribute 'multiply'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[32], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Cell with import error\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[43mAD450_math\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmultiply\u001b[49m(\u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m2\u001b[39m)\n", + "\u001b[0;31mAttributeError\u001b[0m: module 'AD450_math' has no attribute 'multiply'" + ] + } + ], "source": [ "# Cell with import error\n", "AD450_math.multiply(2, 2)" @@ -369,7 +652,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -378,9 +661,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "AttributeError", + "evalue": "module 'AD450_math' has no attribute 'multiply'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[34], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Cell with correct output \u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[43mAD450_math\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmultiply\u001b[49m(\u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m2\u001b[39m)\n", + "\u001b[0;31mAttributeError\u001b[0m: module 'AD450_math' has no attribute 'multiply'" + ] + } + ], "source": [ "# Cell with correct output \n", "AD450_math.multiply(2, 2)" @@ -431,7 +726,7 @@ "provenance": [] }, "kernelspec": { - "display_name": "my_env_2", + "display_name": "ml-env", "language": "python", "name": "python3" }, @@ -445,7 +740,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.16" + "version": "3.10.18" } }, "nbformat": 4, From 7b40d019a88f366c24cf518b8151162b1d427b3a Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Wed, 7 Jan 2026 03:58:05 -0800 Subject: [PATCH 02/17] finished week_2 assignment --- AD450_math.py | 3 +- week_2_intro_ipython.ipynb | 78 ++++++++++++++++++++++++++------------ 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/AD450_math.py b/AD450_math.py index 911df99..481036f 100644 --- a/AD450_math.py +++ b/AD450_math.py @@ -2,4 +2,5 @@ def add(num1, num2): return num1 + num2 def multiply(num1, num2): - return num1 * num2 \ No newline at end of file + return num1 * num2 + diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index bb7ba0e..894b64b 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -554,7 +554,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 6, "metadata": { "id": "p0YE0nqs4Hcz" }, @@ -597,7 +597,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -606,7 +606,7 @@ "4" ] }, - "execution_count": 23, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -614,7 +614,7 @@ "source": [ "import AD450_math\n", "\n", - "AD450_math.add(2,2)" + "AD450_math.add(2,2)\n" ] }, { @@ -630,7 +630,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -640,7 +640,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[32], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Cell with import error\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[43mAD450_math\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmultiply\u001b[49m(\u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m2\u001b[39m)\n", + "Cell \u001b[0;32mIn[2], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Cell with import error\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[43mAD450_math\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmultiply\u001b[49m(\u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m2\u001b[39m)\n", "\u001b[0;31mAttributeError\u001b[0m: module 'AD450_math' has no attribute 'multiply'" ] } @@ -652,28 +652,40 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Reload cell" + "# Reload cell\n", + "import importlib\n", + "importlib.reload(AD450_math)\n" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 6, "metadata": {}, "outputs": [ { - "ename": "AttributeError", - "evalue": "module 'AD450_math' has no attribute 'multiply'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[34], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Cell with correct output \u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[43mAD450_math\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmultiply\u001b[49m(\u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m2\u001b[39m)\n", - "\u001b[0;31mAttributeError\u001b[0m: module 'AD450_math' has no attribute 'multiply'" - ] + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -695,20 +707,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "# Create a" + "# Create a\n", + "a = 1" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], "source": [ - "# Print a" + "# Print a\n", + "print(a)" ] }, { @@ -717,7 +739,13 @@ "metadata": {}, "outputs": [], "source": [ - "# Set a to 4" + "# Set a to 4\n", + "a = 4\n", + "\n", + "\"\"\" \n", + "It looks like after running this block that it is changing the global value of a. \n", + "so when we run the block above it prints out 4 because a has been re-assigned.\n", + "\"\"\";" ] } ], From 63131b994c7ab947a366e732870fb746097d73fd Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Wed, 7 Jan 2026 04:00:47 -0800 Subject: [PATCH 03/17] updated comment on question 15 --- week_2_intro_ipython.ipynb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index 894b64b..5431b83 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -554,7 +554,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "id": "p0YE0nqs4Hcz" }, @@ -578,14 +578,17 @@ "\n", "print(f\"The {dog['breed']} is expected to live about {dog['Age Exp.']} years.\")\n", "\n", - "# I used AI to help me with this as I kept getting an error on the last print statement \n", - "# because I was using double quotes for the variable I was placing inside the f-string. \n", - "# I was trying to access it like this dog[\"breed\"] but kept getting an error. So I pasted \n", - "# it into gpt and it explained that the interpreter was interpreting the first double \n", - "# quotation mark as the end of the f-string. Thus causing the error.\n", + "\"\"\"\n", + "I used AI to help me with this as I kept getting an error on the last print statement \n", + "because I was using double quotes for the variable I was placing inside the f-string. \n", + "I was trying to access it like this dog[\"breed\"] but kept getting an error. So I pasted \n", + "it into gpt and it explained that the interpreter was interpreting the first double \n", + "quotation mark as the end of the f-string. Thus causing the error. \n", "\n", - "# I also learned that in juypter you can't use multi-line comments in juypter notebooks \n", - "# by using the triple quotes before and after a comment\n" + "I also learned that juypter notebook is finicky about mutli-line comments and you have \n", + "to add a semi-colon after the second triple quote otherwise it will print your comment. \n", + "\"\"\";\n", + "\n" ] }, { From 9eca43bb2ecb57d6135bd0ec1e97ebfb0b2935e7 Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Thu, 8 Jan 2026 16:19:17 -0800 Subject: [PATCH 04/17] updated a comment --- week_2_intro_ipython.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index 5431b83..2edadce 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -738,7 +738,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ From ed43ba57662989df074271fe79e6593b4352c512 Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Tue, 13 Jan 2026 17:23:44 -0800 Subject: [PATCH 05/17] first commit for week2 --- week_2_intro_ipython.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index 2edadce..ad1b663 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "id": "BQybla17FRh5" }, @@ -39,7 +39,7 @@ } ], "source": [ - "name = \"Joe\"\n", + "name = \"Joee\"\n", "\n", "print(f\"My name is {name}.\")\n", "print(\"I am a student at North Seattle College.\")" From 6faf1054c3521d5ffee5e0051a4cc252ff9816cd Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Tue, 13 Jan 2026 17:37:39 -0800 Subject: [PATCH 06/17] fixed name type --- week_2_intro_ipython.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index ad1b663..73ccd25 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -39,7 +39,7 @@ } ], "source": [ - "name = \"Joee\"\n", + "name = \"Joe\"\n", "\n", "print(f\"My name is {name}.\")\n", "print(\"I am a student at North Seattle College.\")" From 411ed8a0c45e273648965853dc658e6c1761b3be Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Tue, 13 Jan 2026 18:32:16 -0800 Subject: [PATCH 07/17] fixed issue with problem 10 --- week_2_intro_ipython.ipynb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index 73ccd25..4a3bb1d 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -351,7 +351,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 6, "metadata": { "id": "4a1D64hpFRiA" }, @@ -360,16 +360,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "3\n", - "6\n", - "9\n" + "3 6 9 \n", + "18\n" ] } ], "source": [ + "sum = 0\n", "for i in range(1,11):\n", " if i % 3 == 0:\n", - " print(i)" + " print(i, end= \" \")\n", + " sum += i\n", + "\n", + "print(f\"\\n{sum}\")" ] }, { From 23d9af13a793fe314faee034eec99abdef55bc27 Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Wed, 14 Jan 2026 02:00:36 -0800 Subject: [PATCH 08/17] fixed a few issues where I didn't follow directions correctly --- week_2_intro_ipython.ipynb | 55 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index 4a3bb1d..4eee6b3 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "BQybla17FRh5" }, @@ -39,10 +39,7 @@ } ], "source": [ - "name = \"Joe\"\n", - "\n", - "print(f\"My name is {name}.\")\n", - "print(\"I am a student at North Seattle College.\")" + "print(f\"My name is Joe.\\nI am a student at North Seattle College.\")" ] }, { @@ -57,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": { "id": "P7QDyWncFRh8" }, @@ -66,12 +63,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "My phone numberis 206-555-5555\n" + "My phone numberis 2065555555\n" ] } ], "source": [ - "phone_num = \"206-555-5555\"\n", + "phone_num = \"2065555555\"\n", "\n", "print(f\"My phone numberis {phone_num}\")" ] @@ -88,7 +85,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "metadata": { "id": "OnOau948FRh9" }, @@ -102,7 +99,10 @@ } ], "source": [ - "print(f\"Hello my name is {name} and my phone number is {phone_num}\")" + "phone = \"206-555-5555\"\n", + "name = \"Joe\"\n", + "\n", + "print(f\"Hello my name is {name} and my phone number is {phone}\")" ] }, { @@ -118,7 +118,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 8, "metadata": { "id": "5x2rIFzRFRh9" }, @@ -132,8 +132,7 @@ } ], "source": [ - "month = \"June\"\n", - "year = 2027 \n", + "month, year = \"June\", 2027\n", "\n", "print(f\"I graduate in {month} of {year}.\")" ] @@ -273,7 +272,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 10, "metadata": { "id": "1vxg4nMbFRh_" }, @@ -290,7 +289,9 @@ "source": [ "y = 70\n", "\n", - "if y % 5 == 0 and y % 10 == 0:\n", + "# you only need to check for mod 10 below becuase if it is divisible by 10 then \n", + "# it is also divisible by 5\n", + "if y % 10 == 0:\n", " print(\"Number is divisible by 5 and 10.\")\n", "\n", "if y % 7 == 0 or y % 2 == 0:\n", @@ -351,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 13, "metadata": { "id": "4a1D64hpFRiA" }, @@ -367,10 +368,13 @@ ], "source": [ "sum = 0\n", - "for i in range(1,11):\n", + "i = 1\n", + "\n", + "while i < 11:\n", " if i % 3 == 0:\n", " print(i, end= \" \")\n", " sum += i\n", + " i += 1\n", "\n", "print(f\"\\n{sum}\")" ] @@ -481,7 +485,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 16, "metadata": { "id": "zw2NezoM0zfl" }, @@ -490,19 +494,15 @@ "name": "stdout", "output_type": "stream", "text": [ - "Thor is a character in the Marvel Cinematic Universe. She-Hulk is a character in the Marvel Cinematic Universe. Loki is a character in the Marvel Cinematic Universe. \n" + "Thor is a character in the Marvel Cinematic Universe. She-Hulk is a character in the Marvel Cinematic Universe. Loki is a character in the Marvel Cinematic Universe. " ] } ], "source": [ "chars = [\"Thor\", \"She-Hulk\", \"Loki\"]\n", - "output = \"\"\n", - "\n", - "for i in range(len(chars)):\n", - " output += chars[i]\n", - " output += \" is a character in the Marvel Cinematic Universe. \"\n", "\n", - "print(output)" + "for name in chars:\n", + " print(f\"{name} is a character in the Marvel Cinematic Universe.\", end = \" \")\n" ] }, { @@ -517,7 +517,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 19, "metadata": { "id": "rbyZif9a1b2V" }, @@ -539,7 +539,8 @@ "months = [[\"January\", 31], [\"February\", 28], [\"March\", 31], [\"April\", 30], [\"May\", 31], [\"June\", 30]]\n", "\n", "for i in range(len(months)):\n", - " print(f\"{months[i][0]} has {months[i][1]} days. \")" + " month, days = months[i][0], months[i][1]\n", + " print(f\"{month} has {days} days. \")" ] }, { From f058899c48f56ca0bb19e37df67fb675163a693b Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Wed, 14 Jan 2026 02:03:18 -0800 Subject: [PATCH 09/17] fixed type on problem #2 --- week_2_intro_ipython.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index 4eee6b3..ca1b174 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -54,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "id": "P7QDyWncFRh8" }, @@ -70,7 +70,7 @@ "source": [ "phone_num = \"2065555555\"\n", "\n", - "print(f\"My phone numberis {phone_num}\")" + "print(f\"My phone number is {phone_num}\")" ] }, { From 8011768acb8102cbe32438e0b9ed2c6434516717 Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Wed, 14 Jan 2026 02:04:30 -0800 Subject: [PATCH 10/17] fogot to save changes to typo fix on problem #2 --- week_2_intro_ipython.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index ca1b174..e6bf222 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -54,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "id": "P7QDyWncFRh8" }, @@ -63,7 +63,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "My phone numberis 2065555555\n" + "My phone number is 2065555555\n" ] } ], From 39bcf659a19439ebd01dfe494f456221bfdd5962 Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Fri, 16 Jan 2026 03:23:48 -0800 Subject: [PATCH 11/17] completed first couple of problems --- week_3_numpy.ipynb | 114 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 90 insertions(+), 24 deletions(-) diff --git a/week_3_numpy.ipynb b/week_3_numpy.ipynb index 1db8573..cd28b4e 100644 --- a/week_3_numpy.ipynb +++ b/week_3_numpy.ipynb @@ -57,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": { "id": "Pt63xmy1qLll" }, @@ -75,7 +75,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -83,19 +83,37 @@ "id": "AVByQUYKxtNG", "outputId": "238e50f0-366d-41de-a44a-6cf3e063650c" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1 2 3 4]\n", + " [5 6 7 8]]\n", + "\n", + "Inspect the array\n", + "--------------\n", + "dimensions: 2\n", + "shape:\t (2, 4)\n", + "size:\t 8\n", + "datatype int64\n", + "bytes:\t 64\n" + ] + } + ], "source": [ "# create an array called numbers with 2 rows and 4 columns from literal values. Have your literal values be the integers 1-8\n", - "numbers = None #Replace None with array defintion\n", + "numbers = np.array([[1,2,3,4], [5,6,7,8]])\n", + "\n", "print(numbers)\n", "\n", "# Replace None below with each value for the array. \n", "print(\"\\nInspect the array\\n--------------\")\n", - "print(\"dimensions:\", None) # ndarrays have dimensions\n", - "print(\"shape:\\t\", None) # ndarrays have shape (numer of rows & columns)\n", - "print(\"size:\\t\", None) # number of elements in the array\n", - "print(\"datatype\", None) # numpy determines the datatype\n", - "print(\"bytes:\\t\", None) # total bytes consumed by the array" + "print(\"dimensions:\", numbers.ndim) # ndarrays have dimensions\n", + "print(\"shape:\\t\", numbers.shape) # ndarrays have shape (numer of rows & columns)\n", + "print(\"size:\\t\", numbers.size) # number of elements in the array\n", + "print(\"datatype\", numbers.dtype) # numpy determines the datatype\n", + "print(\"bytes:\\t\", numbers.size * numbers.itemsize) # total bytes consumed by the array" ] }, { @@ -109,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -117,34 +135,76 @@ "id": "pTXgMRYRQS3v", "outputId": "010d4702-bc29-4f87-980e-66fe9b43436a" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ones\n", + "[[1. 1. 1. 1.]\n", + " [1. 1. 1. 1.]\n", + " [1. 1. 1. 1.]] \n", + "\n", + "zeros\n", + "[[0. 0. 0. 0.]\n", + " [0. 0. 0. 0.]\n", + " [0. 0. 0. 0.]] \n", + "\n", + "random\n", + "None \n", + "\n", + "empty\n", + "[[0. 0.]\n", + " [0. 0.]\n", + " [0. 0.]] \n", + "\n", + "full\n", + "[['x' 'x']\n", + " ['x' 'x']] \n", + "\n", + "even\n", + "[10 15 20] \n", + "\n", + "line\n", + "None \n", + "\n" + ] + } + ], "source": [ "# Create an 3 by 4 array of ones\n", - "ones = None\n", + "ones = np.ones((3,4))\n", + "print(\"ones\")\n", "print(ones, \"\\n\")\n", "\n", "# Create an 3 by 4 array of zeros\n", - "zeros = None\n", + "zeros = np.zeros((3,4))\n", + "print(\"zeros\")\n", "print(zeros, \"\\n\")\n", "\n", "# Create an 2 by 2 array with random values\n", "rando = None\n", + "print(\"random\")\n", "print(rando, \"\\n\")\n", "\n", "# Create 3 by 2 an empty array\n", - "empty = None\n", + "empty = np.empty((3,2))\n", + "print(\"empty\")\n", "print(empty, \"\\n\")\n", "\n", "# Create a 2 by 2 array full of 'x's, hint seach numpy full\n", - "full = None\n", + "full = np.full((2,2),'x')\n", + "print(\"full\")\n", "print(full, \"\\n\")\n", "\n", "# Create an array of the form [10, 15, 20] using np.arange\n", - "even = None\n", + "even = np.arange(10,21,5)\n", + "print(\"even\")\n", "print(even, \"\\n\")\n", "\n", "# Create an array of the form [0. 0.25 0.5 0.75 1. 1.25 1.5 1.75 2. ] using np.linspace\n", "line = None\n", + "print(\"line\")\n", "print(line, \"\\n\")\n" ] }, @@ -172,7 +232,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 43, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -184,7 +244,9 @@ "source": [ "arr1d = np.array([0,1, 2, 3, 4, 5, 6, 7, 8])\n", "\n", - "# using indexing select and output [5, 6, 7] from arr1d. Save this slice to a variable named slice_arr1d\n" + "# using indexing select and output [5, 6, 7] from arr1d. Save this slice to a variable named slice_arr1d\n", + "\n", + "slice_arr1d = arr1d[5:8]\n" ] }, { @@ -196,7 +258,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 46, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -206,7 +268,9 @@ }, "outputs": [], "source": [ - "# Replace 6, 7, and 8 with 12 in arr1d using one line of code. Then print arr1d and slice_arr1d\n" + "# Replace 6, 7, and 8 with 12 in arr1d using one line of code. Then print arr1d and slice_arr1d\n", + "\n", + "arr1d[6:] = 12\n" ] }, { @@ -218,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 48, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -228,7 +292,9 @@ }, "outputs": [], "source": [ - "# Create a copy of arr1d and name it new_array. Hint: You can't use new_array = arr1d" + "# Create a copy of arr1d and name it new_array. Hint: You can't use new_array = arr1d\n", + "\n", + "new_array = arr1d.copy()" ] }, { @@ -664,7 +730,7 @@ "provenance": [] }, "kernelspec": { - "display_name": "base", + "display_name": "ml-env", "language": "python", "name": "python3" }, @@ -678,7 +744,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "version": "3.10.18" } }, "nbformat": 4, From cb80c5c631c60eeb78ffc83ca71228a14a8d75a4 Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Sat, 17 Jan 2026 06:55:53 -0800 Subject: [PATCH 12/17] finished problem 3 --- week_3_numpy.ipynb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/week_3_numpy.ipynb b/week_3_numpy.ipynb index cd28b4e..03564c8 100644 --- a/week_3_numpy.ipynb +++ b/week_3_numpy.ipynb @@ -57,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": { "id": "Pt63xmy1qLll" }, @@ -127,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -151,7 +151,8 @@ " [0. 0. 0. 0.]] \n", "\n", "random\n", - "None \n", + "[[ 0.38370392 -0.69051018]\n", + " [-0.69090326 -0.36937786]] \n", "\n", "empty\n", "[[0. 0.]\n", @@ -166,7 +167,7 @@ "[10 15 20] \n", "\n", "line\n", - "None \n", + "[0. 0.25 0.5 0.75 1. 1.25 1.5 1.75 2. ] \n", "\n" ] } @@ -183,7 +184,7 @@ "print(zeros, \"\\n\")\n", "\n", "# Create an 2 by 2 array with random values\n", - "rando = None\n", + "rando = np.random.standard_normal(size = (2,2))\n", "print(\"random\")\n", "print(rando, \"\\n\")\n", "\n", @@ -203,7 +204,7 @@ "print(even, \"\\n\")\n", "\n", "# Create an array of the form [0. 0.25 0.5 0.75 1. 1.25 1.5 1.75 2. ] using np.linspace\n", - "line = None\n", + "line = np.linspace(0, 2, num = 9)\n", "print(\"line\")\n", "print(line, \"\\n\")\n" ] From e2b5b214a2333ab9f45f930590cb7eae579689df Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Sat, 17 Jan 2026 18:26:45 -0800 Subject: [PATCH 13/17] finished problem 7 --- week_3_numpy.ipynb | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/week_3_numpy.ipynb b/week_3_numpy.ipynb index 03564c8..8e18d61 100644 --- a/week_3_numpy.ipynb +++ b/week_3_numpy.ipynb @@ -307,13 +307,25 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "3\n" + ] + } + ], "source": [ "arr2d = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])\n", "\n", - "# There are two ways to select 3 from the 2 dimensional array above. Use both ways to select 3 and print the results. " + "# There are two ways to select 3 from the 2 dimensional array above. Use both ways to select 3 and print the results. \n", + "\n", + "print(arr2d[0][2])\n", + "print(arr2d[0,2])" ] }, { @@ -325,7 +337,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 25, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -333,16 +345,33 @@ "id": "kvMvyar216T5", "outputId": "943f42a4-469a-48f0-f4d4-546849ffa08d" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[2 3 4]\n", + " [6 7 8]] \n", + "\n", + "[[3]\n", + " [7]] \n", + "\n", + "[[1 2 3 4]]\n" + ] + } + ], "source": [ "# In mult-dimensional arrays, slicing that omits later indices will return a lower-dimensional ndarray\n", "# Select and print out the following:\n", "\n", "# select first two rows and all but first column\n", + "print(arr2d[:2, 1:], \"\\n\")\n", "\n", "# select first two rows and only 3rd column\n", + "print(arr2d[:2, 2:3], \"\\n\")\n", "\n", - "# select all columns in the first row\n" + "# select all columns in the first row\n", + "print(arr2d[:1, :])\n" ] }, { From 889f1811a00df88863c6690c90f838c68acfad7b Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Sun, 18 Jan 2026 17:19:35 -0800 Subject: [PATCH 14/17] completed through problem 15 --- week_3_numpy.ipynb | 184 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 158 insertions(+), 26 deletions(-) diff --git a/week_3_numpy.ipynb b/week_3_numpy.ipynb index 8e18d61..b1c51a5 100644 --- a/week_3_numpy.ipynb +++ b/week_3_numpy.ipynb @@ -57,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": { "id": "Pt63xmy1qLll" }, @@ -394,7 +394,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 33, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -402,14 +402,38 @@ "id": "IMEp_RGh_Fu5", "outputId": "45332ef8-2c42-4c40-af09-6caaf98bca6b" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "First and fourth rows of data: \n", + "[[0 0 0 0 1 1 1]\n", + " [0 1 1 1 0 1 0]] \n", + "\n", + "All of data: \n", + "[[0 0 0 0 1 1 1]\n", + " [1 1 0 1 1 0 0]\n", + " [1 0 0 0 1 0 1]\n", + " [0 1 1 1 0 1 0]\n", + " [0 1 1 1 1 1 1]\n", + " [0 0 0 0 1 1 0]\n", + " [0 1 0 0 0 0 0]]\n" + ] + } + ], "source": [ "import numpy as np\n", "names = np.array(['Bob', 'Joe', 'Will', 'Bob', 'Will', 'Joe', 'Joe'])\n", "data = np.random.randint(2, size=(7, 7)) # create an array of random values\n", "\n", "# Select and print the first and forth rows from 'data' using just the array 'names' and 'data'. Print out both the selected rows and 'data'. \n", - "# Hint\" The \"Bob\" appears in both the first and forth rows. " + "# Hint\" The \"Bob\" appears in both the first and forth rows. \n", + "\n", + "print(\"First and fourth rows of data: \")\n", + "print(data[names == \"Bob\"], \"\\n\")\n", + "print(\"All of data: \")\n", + "print(data)\n" ] }, { @@ -423,7 +447,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -431,10 +455,22 @@ "id": "BgULatpwt7X_", "outputId": "c31d49b4-92ff-4514-c91b-8eeb42573b5f" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0, 0, 0, 0, 1, 1, 1],\n", + " [0, 1, 1, 1, 0, 1, 0]])" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Again output the first and fouth rows using the cond below. Meaning replace None with an expression\n", - "cond = None\n", + "cond = (names == \"Bob\")\n", "data[cond]" ] }, @@ -449,7 +485,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 35, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -457,9 +493,27 @@ "id": "EP-SDDVIvK8s", "outputId": "cce4fab9-cd5e-46c2-c615-f2518f1b4a72" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1, 1, 0, 1, 1, 0, 0],\n", + " [1, 0, 0, 0, 1, 0, 1],\n", + " [0, 1, 1, 1, 1, 1, 1],\n", + " [0, 0, 0, 0, 1, 1, 0],\n", + " [0, 1, 0, 0, 0, 0, 0]])" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Select all rows except the first and forth" + "# Select all rows except the first and forth\n", + "\n", + "cond = ~(names == \"Bob\")\n", + "data[cond]" ] }, { @@ -473,7 +527,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 36, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -481,9 +535,23 @@ "id": "QYjmF7eFvTmc", "outputId": "172adeb5-31d7-47ad-e3af-59c352f96f97" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1, 1, 1],\n", + " [0, 1, 0]])" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Select the last 5 columns for the first and forth row" + "# Select the last 5 columns for the first and forth row\n", + "cond = (names == \"Bob\")\n", + "data[cond, 4:]" ] }, { @@ -497,7 +565,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 37, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -505,9 +573,26 @@ "id": "sciz0aprvh8u", "outputId": "24c8c092-cbe9-4665-9e01-9d193bcac8df" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0, 0, 0, 0, 1, 1, 1],\n", + " [1, 0, 0, 0, 1, 0, 1],\n", + " [0, 1, 1, 1, 0, 1, 0],\n", + " [0, 1, 1, 1, 1, 1, 1]])" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Select the first, third, forth and fifth row using similar conditioins and an OR operator" + "# Select the first, third, forth and fifth row using similar conditioins and an OR operator\n", + "\n", + "cond = (names == \"Bob\") | (names == \"Will\")\n", + "data[cond]" ] }, { @@ -532,7 +617,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -540,18 +625,39 @@ "id": "HdWTjc8CZI5R", "outputId": "e070b71e-bdee-4abc-f378-474978208ad5" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original array: \n", + "[[1. 2. 3.]\n", + " [4. 5. 6.]] \n", + "\n", + "Adding 5: \n", + "[[ 6. 7. 8.]\n", + " [ 9. 10. 11.]] \n", + "\n", + "Multiplying by 10: \n", + "[[10. 20. 30.]\n", + " [40. 50. 60.]]\n" + ] + } + ], "source": [ "array1 = np.array([[1., 2., 3.], [4., 5., 6.]])\n", "\n", - "print(array1)\n", + "print(\"Original array: \")\n", + "print(array1, \"\\n\")\n", "\n", "# Add 5 to all values in array1 and print \n", - "print()\n", + "print(\"Adding 5: \")\n", + "print(array1 + 5, \"\\n\")\n", "\n", "\n", "# Multiple all values in array1 by 10 and print \n", - "print()\n" + "print(\"Multiplying by 10: \")\n", + "print(array1 * 10)\n" ] }, { @@ -565,7 +671,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 48, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -573,9 +679,23 @@ "id": "uHr0DxrmaOEZ", "outputId": "b0f74550-427d-4333-c010-45f886677379" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[False True False]\n", + " [ True False True]]\n" + ] + } + ], "source": [ + "# array1 = np.array([[1., 2., 3.], [4., 5., 6.]])\n", + "\n", "array2 = np.array([[0., 4., 1.], [7., 2., 12.]])\n", + "result14 = np.where(array1 < array2, True, False)\n", + "\n", + "print(result14)\n", "\n", "\n", "# Test to see if pairwise elements in array1 are less than the corresponding element in array2. Output the results.\n", @@ -615,7 +735,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 49, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -623,13 +743,25 @@ "id": "k5pIynI12dmY", "outputId": "cd39dc42-7bab-4a92-c3e0-151a287d0b07" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1. 0. 1. 1. 0.]\n" + ] + } + ], "source": [ "arr1 = np.ones(5)\n", "arr2 = np.zeros(5)\n", "cond = np.array([True, False, True, True, False])\n", "\n", - "# Output the value from `arr1` whenever the corresponding value in `cond` is True, and otherwise take the value from `arr2`. \n" + "# Output the value from `arr1` whenever the corresponding value in `cond` is True, and otherwise take the value from `arr2`. \n", + "\n", + "result15 = np.where(cond, arr1, arr2)\n", + "\n", + "print(result15)\n" ] }, { From 0e59c04083acac8602280a0ac5b57a010274b401 Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Mon, 19 Jan 2026 04:17:27 -0800 Subject: [PATCH 15/17] finished --- week_3_numpy.ipynb | 125 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 110 insertions(+), 15 deletions(-) diff --git a/week_3_numpy.ipynb b/week_3_numpy.ipynb index b1c51a5..d026fbd 100644 --- a/week_3_numpy.ipynb +++ b/week_3_numpy.ipynb @@ -57,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": { "id": "Pt63xmy1qLll" }, @@ -792,7 +792,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -800,12 +800,33 @@ "id": "ImvBT7NX3aY7", "outputId": "d04b3b76-91e4-4a40-e047-1e7a55bfd4ed" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0 3 3 3]\n", + " [0 3 1 0]\n", + " [1 1 1 2]\n", + " [3 3 2 0]\n", + " [1 3 2 0]] \n", + "\n", + "Mean: 1.6\n", + "Sum: 32\n" + ] + } + ], "source": [ "arr = np.random.randint(4, size=(5, 4))\n", - "print(arr)\n", + "print(arr, \"\\n\")\n", "\n", - "# Calculate and print the mean and sum for all values in the array\n" + "# Calculate and print the mean and sum for all values in the array\n", + "\n", + "mean16 = np.mean(arr)\n", + "sum16 = arr.sum()\n", + "\n", + "print(\"Mean: \", mean16)\n", + "print(\"Sum: \", sum16)\n" ] }, { @@ -817,7 +838,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -825,9 +846,32 @@ "id": "kxw7AUVm31Ea", "outputId": "b1cb6ece-5056-41b1-8c1b-f57612b9dae1" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean across rows: [2.25 1. 1.25 2. 1.5 ]\n", + "Mean across columns: [1. 2.6 1.8 1. ]\n", + "Sum across rows: [9 4 5 8 6]\n", + "Sum across columns: [ 5 13 9 5]\n" + ] + } + ], "source": [ - "# Calculate the mean and sum across the columns and the rows. Print out both\n" + "# Calculate the mean and sum across the columns and the rows. Print out both\n", + "# axis = 0 columns \n", + "# axis = 1 rows \n", + "\n", + "mean17_rows = arr.mean(axis = 1)\n", + "mean17_columns = arr.mean(axis = 0)\n", + "sum17_rows = arr.sum(axis = 1)\n", + "sum17_columns = arr.sum(axis = 0)\n", + "\n", + "print(\"Mean across rows: \", mean17_rows)\n", + "print(\"Mean across columns: \", mean17_columns)\n", + "print(\"Sum across rows: \", sum17_rows)\n", + "print(\"Sum across columns: \", sum17_columns)\n" ] }, { @@ -839,15 +883,46 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Full cummulative sum: \n", + " [ 0 3 6 9 9 12 13 13 14 15 16 18 21 24 26 26 27 30 32 32] \n", + "\n", + "Columns cumulative sum: \n", + " [[ 0 3 3 3]\n", + " [ 0 6 4 3]\n", + " [ 1 7 5 5]\n", + " [ 4 10 7 5]\n", + " [ 5 13 9 5]] \n", + "\n", + "Rows cumulative sum: \n", + " [[0 3 6 9]\n", + " [0 3 4 4]\n", + " [1 2 3 5]\n", + " [3 6 8 8]\n", + " [1 4 6 6]]\n" + ] + } + ], "source": [ "# Print out the cumulative sum for the full array, the columns and the rows. \n", "# For example the array [[1, 1, 1], [1, 1, 1]] would have the following outputs:\n", "# full array: [1, 2, 3, 4, 5, 6]\n", "# columns: [[1, 1, 1], [2, 2, 2]]\n", - "# rows: [[1, 2, 3], [1, 2, 3]]\n" + "# rows: [[1, 2, 3], [1, 2, 3]]\n", + "\n", + "cumsum18_full = arr.cumsum()\n", + "cumsum18_columns = arr.cumsum(axis = 0)\n", + "cumsum18_rows = arr.cumsum(axis = 1)\n", + "\n", + "print(\"Full cummulative sum: \\n\", cumsum18_full, \"\\n\")\n", + "print(\"Columns cumulative sum: \\n\", cumsum18_columns, \"\\n\")\n", + "print(\"Rows cumulative sum: \\n\", cumsum18_rows)\n" ] }, { @@ -859,7 +934,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -867,16 +942,36 @@ "id": "sDnJpvUR1B1W", "outputId": "c4806b83-0ba9-448e-c4b7-f9ca53a8900d" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Arr: \n", + " [0 1 2 3 4 5 6 7 8 9] \n", + "\n", + "Odds: \n", + " [1 3 5 7 9] \n", + "\n", + "Arr reversed: \n", + " [9 8 7 6 5 4 3 2 1 0]\n" + ] + } + ], "source": [ "\n", "arr = np.arange(10)\n", - "print(arr)\n", + "print(\"Arr: \\n\", arr, \"\\n\")\n", "\n", "\n", "# Print out all all odd values\n", + "cond19 = arr % 2 \n", + "\n", + "odds = arr[arr % 2 == 1]\n", + "print(\"Odds: \\n\", odds, \"\\n\")\n", "\n", - "# Print out all values in reverse order\n" + "# Print out all values in reverse order\n", + "print(\"Arr reversed: \\n\", np.flip(arr))\n" ] } ], From dc217abd31aaacae21f18e606c46bb3dd27c0328 Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Mon, 19 Jan 2026 04:20:32 -0800 Subject: [PATCH 16/17] initial week3 commit with new branch that is branched off of the homework branch --- week_3_numpy.ipynb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/week_3_numpy.ipynb b/week_3_numpy.ipynb index d026fbd..879c7bf 100644 --- a/week_3_numpy.ipynb +++ b/week_3_numpy.ipynb @@ -934,7 +934,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -965,8 +965,6 @@ "\n", "\n", "# Print out all all odd values\n", - "cond19 = arr % 2 \n", - "\n", "odds = arr[arr % 2 == 1]\n", "print(\"Odds: \\n\", odds, \"\\n\")\n", "\n", From 9fb3822a0394388523a57c430957877b2fa5b3f7 Mon Sep 17 00:00:00 2001 From: Joe Klinck Date: Wed, 21 Jan 2026 01:50:01 -0800 Subject: [PATCH 17/17] fixed a couple issues --- week_3_numpy.ipynb | 127 ++++++++++++++++++++++++++++----------------- 1 file changed, 79 insertions(+), 48 deletions(-) diff --git a/week_3_numpy.ipynb b/week_3_numpy.ipynb index 879c7bf..cd71e72 100644 --- a/week_3_numpy.ipynb +++ b/week_3_numpy.ipynb @@ -20,6 +20,11 @@ "* Can map data directly onto underlying disk or memory representation\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, { "cell_type": "markdown", "metadata": { @@ -75,7 +80,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -113,7 +118,7 @@ "print(\"shape:\\t\", numbers.shape) # ndarrays have shape (numer of rows & columns)\n", "print(\"size:\\t\", numbers.size) # number of elements in the array\n", "print(\"datatype\", numbers.dtype) # numpy determines the datatype\n", - "print(\"bytes:\\t\", numbers.size * numbers.itemsize) # total bytes consumed by the array" + "print(\"bytes:\\t\", numbers.nbytes) # total bytes consumed by the array" ] }, { @@ -127,7 +132,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -151,8 +156,8 @@ " [0. 0. 0. 0.]] \n", "\n", "random\n", - "[[ 0.38370392 -0.69051018]\n", - " [-0.69090326 -0.36937786]] \n", + "[[0.52286842 0.27818666]\n", + " [1.20170613 0.13236204]] \n", "\n", "empty\n", "[[0. 0.]\n", @@ -204,7 +209,7 @@ "print(even, \"\\n\")\n", "\n", "# Create an array of the form [0. 0.25 0.5 0.75 1. 1.25 1.5 1.75 2. ] using np.linspace\n", - "line = np.linspace(0, 2, num = 9)\n", + "line = np.linspace(0, 2, 9)\n", "print(\"line\")\n", "print(line, \"\\n\")\n" ] @@ -233,7 +238,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -241,13 +246,22 @@ "id": "NSMJt_4x0qan", "outputId": "81e81c55-af1d-4149-dc7c-7edc8a1a582d" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[5 6 7]\n" + ] + } + ], "source": [ "arr1d = np.array([0,1, 2, 3, 4, 5, 6, 7, 8])\n", "\n", "# using indexing select and output [5, 6, 7] from arr1d. Save this slice to a variable named slice_arr1d\n", "\n", - "slice_arr1d = arr1d[5:8]\n" + "slice_arr1d = arr1d[5:8]\n", + "print(slice_arr1d)\n" ] }, { @@ -259,7 +273,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -267,11 +281,20 @@ "id": "Xe-PXYhBp4bn", "outputId": "cf387d7a-d51f-4540-8d9a-571a9a24f7b5" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 0 1 2 3 4 5 12 12 12]\n" + ] + } + ], "source": [ "# Replace 6, 7, and 8 with 12 in arr1d using one line of code. Then print arr1d and slice_arr1d\n", "\n", - "arr1d[6:] = 12\n" + "arr1d[6:] = 12\n", + "print(arr1d)\n" ] }, { @@ -283,7 +306,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 6, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -291,11 +314,20 @@ "id": "Eh0My7Eaqe77", "outputId": "693ef4b3-97a0-4a42-d77a-740fa2cd81db" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 0 1 2 3 4 5 12 12 12]\n" + ] + } + ], "source": [ "# Create a copy of arr1d and name it new_array. Hint: You can't use new_array = arr1d\n", "\n", - "new_array = arr1d.copy()" + "new_array = arr1d.copy()\n", + "print(new_array)" ] }, { @@ -307,7 +339,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -337,7 +369,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -353,10 +385,9 @@ "[[2 3 4]\n", " [6 7 8]] \n", "\n", - "[[3]\n", - " [7]] \n", + "[3 7] \n", "\n", - "[[1 2 3 4]]\n" + "[1 2 3 4]\n" ] } ], @@ -368,10 +399,10 @@ "print(arr2d[:2, 1:], \"\\n\")\n", "\n", "# select first two rows and only 3rd column\n", - "print(arr2d[:2, 2:3], \"\\n\")\n", + "print(arr2d[:2, 2], \"\\n\")\n", "\n", "# select all columns in the first row\n", - "print(arr2d[:1, :])\n" + "print(arr2d[0, :])\n" ] }, { @@ -394,7 +425,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 12, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -408,17 +439,17 @@ "output_type": "stream", "text": [ "First and fourth rows of data: \n", - "[[0 0 0 0 1 1 1]\n", - " [0 1 1 1 0 1 0]] \n", + "[[1 0 0 0 0 1 1]\n", + " [0 1 1 1 0 0 0]] \n", "\n", "All of data: \n", - "[[0 0 0 0 1 1 1]\n", - " [1 1 0 1 1 0 0]\n", - " [1 0 0 0 1 0 1]\n", - " [0 1 1 1 0 1 0]\n", - " [0 1 1 1 1 1 1]\n", - " [0 0 0 0 1 1 0]\n", - " [0 1 0 0 0 0 0]]\n" + "[[1 0 0 0 0 1 1]\n", + " [1 1 0 1 1 1 1]\n", + " [0 1 0 1 0 0 1]\n", + " [0 1 1 1 0 0 0]\n", + " [1 0 1 0 1 1 1]\n", + " [1 1 1 1 1 0 0]\n", + " [1 0 0 1 0 1 0]]\n" ] } ], @@ -447,7 +478,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 13, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -459,11 +490,11 @@ { "data": { "text/plain": [ - "array([[0, 0, 0, 0, 1, 1, 1],\n", - " [0, 1, 1, 1, 0, 1, 0]])" + "array([[1, 0, 0, 0, 0, 1, 1],\n", + " [0, 1, 1, 1, 0, 0, 0]])" ] }, - "execution_count": 34, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -485,7 +516,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 14, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -497,14 +528,14 @@ { "data": { "text/plain": [ - "array([[1, 1, 0, 1, 1, 0, 0],\n", - " [1, 0, 0, 0, 1, 0, 1],\n", - " [0, 1, 1, 1, 1, 1, 1],\n", - " [0, 0, 0, 0, 1, 1, 0],\n", - " [0, 1, 0, 0, 0, 0, 0]])" + "array([[1, 1, 0, 1, 1, 1, 1],\n", + " [0, 1, 0, 1, 0, 0, 1],\n", + " [1, 0, 1, 0, 1, 1, 1],\n", + " [1, 1, 1, 1, 1, 0, 0],\n", + " [1, 0, 0, 1, 0, 1, 0]])" ] }, - "execution_count": 35, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -527,7 +558,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 15, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -539,11 +570,11 @@ { "data": { "text/plain": [ - "array([[1, 1, 1],\n", - " [0, 1, 0]])" + "array([[0, 0, 0, 1, 1],\n", + " [1, 1, 0, 0, 0]])" ] }, - "execution_count": 36, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -551,7 +582,7 @@ "source": [ "# Select the last 5 columns for the first and forth row\n", "cond = (names == \"Bob\")\n", - "data[cond, 4:]" + "data[cond, 2:]" ] }, {