From cb79fc36071209c64b900a46075c60bb7c2ed065 Mon Sep 17 00:00:00 2001
From: Jeanette Lee <jeanette.lee@stud.hslu.ch>
Date: Fri, 11 Mar 2022 19:12:32 +0000
Subject: [PATCH] Problem 1 solved

---
 .../Exercise Sheet - Basics Numpy.ipynb       | 40 +++++++++++--------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/notebooks/Block_0/Exercise Sheet - Basics Numpy.ipynb b/notebooks/Block_0/Exercise Sheet - Basics Numpy.ipynb
index 5531ef0..bc23d73 100644
--- a/notebooks/Block_0/Exercise Sheet - Basics Numpy.ipynb	
+++ b/notebooks/Block_0/Exercise Sheet - Basics Numpy.ipynb	
@@ -16,23 +16,24 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": 5,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "Input as Array: None\n",
-      "Input minus min: None\n",
-      "Input  Array: None\n",
+      "Input as Array: [[-1  2  7]]\n",
+      "Input minus min: [[0 3 8]]\n",
+      "Input  Array: [[0.    0.375 1.   ]]\n",
       "Multiply 1:\n",
-      "None\n",
+      "False\n",
       "Multiply 2:\n",
-      "None\n",
+      "[[14]\n",
+      " [32]]\n",
       "Multiply 3:\n",
-      "None\n",
-      "Mean == None\n"
+      "[[ 9 12 15]]\n",
+      "Mean == 2.6666666666666665\n"
      ]
     }
    ],
@@ -43,17 +44,19 @@
     "def prepare_inputs(inputs):\n",
     "    # TODO: create a 2-dimensional ndarray from the given 1-dimensional list;\n",
     "    #       assign it to input_array\n",
-    "    input_array = None\n",
+    "    input_array = np.reshape(inputs, (1, len(inputs)))\n",
     "    \n",
     "    # TODO: find the minimum value in input_array and subtract that\n",
     "    #       value from all the elements of input_array. Store the\n",
     "    #       result in inputs_minus_min\n",
-    "    inputs_minus_min = None\n",
+    "    min_val = input_array.min()\n",
+    "    inputs_minus_min = input_array - min_val\n",
     "\n",
     "    # TODO: find the maximum value in inputs_minus_min and divide\n",
     "    #       all of the values in inputs_minus_min by the maximum value.\n",
     "    #       Store the results in inputs_div_max.\n",
-    "    inputs_div_max = None\n",
+    "    max_val = inputs_minus_min.max()\n",
+    "    inputs_div_max = inputs_minus_min / max_val\n",
     "\n",
     "    # return the three arrays we've created\n",
     "    return input_array, inputs_minus_min, inputs_div_max\n",
@@ -65,18 +68,21 @@
     "    #\n",
     "    #       Return False if the shapes cannot be used for matrix\n",
     "    #       multiplication. You may not use a transpose\n",
-    "    pass\n",
-    "\n",
+    "    if (np.shape(m1)[1] != np.shape(m2)[0]) & (np.shape(m1)[0] != np.shape(m2)[1]):\n",
+    "        return False\n",
     "\n",
     "    # TODO: If you have not returned False, then calculate the matrix product\n",
     "    #       of m1 and m2 and return it. Do not use a transpose,\n",
     "    #       but you swap their order if necessary\n",
-    "    pass\n",
+    "    elif (np.shape(m1)[1] == np.shape(m2)[0]):\n",
+    "        return np.matmul(m1, m2)\n",
+    "    else:\n",
+    "        return np.matmul(m2, m1)\n",
     "    \n",
     "\n",
     "def find_mean(values):\n",
     "    # TODO: Return the average of the values in the given Python list\n",
-    "    pass\n",
+    "    return sum(values) / len(values)\n",
     "\n",
     "\n",
     "input_array, inputs_minus_min, inputs_div_max = prepare_inputs([-1,2,7])\n",
@@ -451,7 +457,7 @@
  ],
  "metadata": {
   "kernelspec": {
-   "display_name": "Python 3",
+   "display_name": "Python 3 (ipykernel)",
    "language": "python",
    "name": "python3"
   },
@@ -465,7 +471,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.7.6"
+   "version": "3.9.7"
   }
  },
  "nbformat": 4,
-- 
GitLab