diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 46f5aa14..427a26f0 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -16,11 +16,11 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "import numpy as np\n" ] }, { @@ -34,11 +34,19 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2.1.3\n" + ] + } + ], "source": [ - "### [your code here]\n" + "print(np.__version__)" ] }, { @@ -51,11 +59,12 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "a = np.random.randint(3, size=(2, 3, 5))\n", + "# I would know how to convert a list into an array, but idk how to do it with random numbers only filling out the numbers myself." ] }, { @@ -68,11 +77,26 @@ }, { "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[2 2 1 0 1]\n", + " [0 1 0 2 2]\n", + " [1 2 2 0 0]]\n", + "\n", + " [[2 2 2 1 1]\n", + " [0 2 2 0 2]\n", + " [0 2 0 2 2]]]\n" + ] + } + ], + "source": [ + "print(a)\n", + "\n" ] }, { @@ -85,11 +109,12 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "\n", + "b = np.ones((5, 2, 3))" ] }, { @@ -102,11 +127,32 @@ }, { "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]]\n" + ] + } + ], + "source": [ + "print(b)\n" ] }, { @@ -119,11 +165,28 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 20, "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "30\n", + "30\n", + "They are the same size\n" + ] + } + ], + "source": [ + "print(a.size)\n", + "print(b.size)\n", + "if a.size == b.size:\n", + " print(\"They are the same size\")\n", + "else:\n", + " print(\"They are not the same size\")\n", + " \n", + "\n" ] }, { @@ -136,11 +199,11 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "# Can't sum, shapes most be the same \n" ] }, { @@ -154,11 +217,21 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(2, 3, 5)\n" + ] + } + ], "source": [ - "### [your code here]\n" + "# We are reshaping at the same time as we are transposing\n", + "c = np.transpose(b,(1,2,0))\n", + "print(c.shape)" ] }, { @@ -171,11 +244,26 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[3. 3. 2. 1. 2.]\n", + " [1. 2. 1. 3. 3.]\n", + " [2. 3. 3. 1. 1.]]\n", + "\n", + " [[3. 3. 3. 2. 2.]\n", + " [1. 3. 3. 1. 3.]\n", + " [1. 3. 1. 3. 3.]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "d = (a + c)\n", + "print(d)\n" ] }, { @@ -188,12 +276,37 @@ }, { "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n", - "\n" + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[2 2 1 0 1]\n", + " [0 1 0 2 2]\n", + " [1 2 2 0 0]]\n", + "\n", + " [[2 2 2 1 1]\n", + " [0 2 2 0 2]\n", + " [0 2 0 2 2]]]\n", + "[[[3. 3. 2. 1. 2.]\n", + " [1. 2. 1. 3. 3.]\n", + " [2. 3. 3. 1. 1.]]\n", + "\n", + " [[3. 3. 3. 2. 2.]\n", + " [1. 3. 3. 1. 3.]\n", + " [1. 3. 1. 3. 3.]]]\n" + ] + } + ], + "source": [ + "print(a)\n", + "print(d)\n", + "# It has the same data type\n", + "# It has the same value numbers\n", + "# The order of value numbers are different\n", + "# The quantity of repeated numbers is different\n" ] }, { @@ -206,11 +319,26 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 36, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[2. 2. 1. 0. 1.]\n", + " [0. 1. 0. 2. 2.]\n", + " [1. 2. 2. 0. 0.]]\n", + "\n", + " [[2. 2. 2. 1. 1.]\n", + " [0. 2. 2. 0. 2.]\n", + " [0. 2. 0. 2. 2.]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "e = a * c\n", + "print(e)\n" ] }, { @@ -224,12 +352,22 @@ }, { "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [], + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "They are equal\n" + ] + } + ], "source": [ - "### [your code here]\n", - "\n" + "\n", + "equal_result =(e == a)\n", + "print(\"They are equal\")\n", + "# e was a multiplication from a and c in which c was only 1s so stayed the same\n" ] }, { @@ -243,12 +381,23 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 50, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max value: 3.0\n", + "Min value: 1.0\n", + "Mean of value: 2.2\n" + ] + } + ], "source": [ - "### [your code here]\n", - "\n" + "d_max = np.max(d); print(\"Max value:\", d_max);\n", + "d_min = np.min(d); print(\"Min value:\", d_min);\n", + "d_mean = np.mean(d); print(\"Mean of value:\", d_mean);\n" ] }, { @@ -261,11 +410,11 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 52, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "f = np.empty((2, 3, 5))\n" ] }, { @@ -287,11 +436,15 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 53, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "f[d == d_min] = 0\n", + "f[d == d_max] = 100\n", + "f[d == d_mean] = 50\n", + "f[(d > d_min) & (d < d_mean)] = 25\n", + "f[(d > d_mean) & (d < d_max)] = 75\n" ] }, { @@ -325,11 +478,33 @@ }, { "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[3. 3. 2. 1. 2.]\n", + " [1. 2. 1. 3. 3.]\n", + " [2. 3. 3. 1. 1.]]\n", + "\n", + " [[3. 3. 3. 2. 2.]\n", + " [1. 3. 3. 1. 3.]\n", + " [1. 3. 1. 3. 3.]]]\n", + "[[[100. 100. 25. 0. 25.]\n", + " [ 0. 25. 0. 100. 100.]\n", + " [ 25. 100. 100. 0. 0.]]\n", + "\n", + " [[100. 100. 100. 25. 25.]\n", + " [ 0. 100. 100. 0. 100.]\n", + " [ 0. 100. 0. 100. 100.]]]\n" + ] + } + ], + "source": [ + "print(d)\n", + "print(f)\n" ] }, { @@ -360,7 +535,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "base", "language": "python", "name": "python3" }, @@ -374,7 +549,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.0" + "version": "3.13.5" } }, "nbformat": 4,