diff --git a/your-code/main.ipynb b/your-code/main.ipynb index e66d6ce..6f2c38f 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -12,11 +12,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "import numpy as np" ] }, { @@ -28,11 +28,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.23.3\n" + ] + } + ], "source": [ - "# your code here" + "print(np.__version__)" ] }, { @@ -45,29 +53,74 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.10734251 0.6360245 0.42336788 0.78543055 0.33726852]\n", + " [0.87775381 0.30222002 0.74441841 0.14602234 0.23671898]\n", + " [0.45065839 0.77676625 0.78701782 0.41264536 0.45710292]]\n", + "\n", + " [[0.55423976 0.15663404 0.43256253 0.50740218 0.34630962]\n", + " [0.73320968 0.17899687 0.05595088 0.37982629 0.5438045 ]\n", + " [0.76321098 0.61181213 0.14385757 0.07156545 0.16344009]]]\n" + ] + } + ], "source": [ - "# Method 1" + "a = np.random.rand(2, 3, 5)\n", + "print(a)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ 0.81193249 -0.76152328 -1.37994571 -1.6152447 -1.21104705]\n", + " [ 0.05273063 0.25450326 -1.39558069 0.39939479 0.29929782]\n", + " [-0.19658269 -0.8504625 -0.50951972 1.10228021 -1.86670971]]\n", + "\n", + " [[-1.34089196 0.65591039 0.35656296 0.45447707 0.10149163]\n", + " [-0.55464493 -0.13966224 -0.54746175 -0.77255666 -0.11729826]\n", + " [ 0.19822701 0.35760714 -1.26557108 0.2190364 0.46443209]]]\n" + ] + } + ], "source": [ - "# Method 2" + "a = np.random.randn(2, 3, 5)\n", + "print(a)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0 7 4 4 3]\n", + " [1 1 7 2 0]\n", + " [7 1 9 5 0]]\n", + "\n", + " [[3 1 8 1 4]\n", + " [2 3 6 6 4]\n", + " [6 3 6 2 6]]]\n" + ] + } + ], "source": [ - "# Method 3" + "a = np.random.randint(0, 10, size=(2, 3, 5))\n", + "print(a)" ] }, { @@ -79,11 +132,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "###Already did above" ] }, { @@ -95,11 +148,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "b = np.ones((5, 2, 3))" ] }, { @@ -111,11 +164,32 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 9, + "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)" ] }, { @@ -127,11 +201,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Shape of a: (2, 3, 5)\n", + "Shape of b: (5, 2, 3)\n" + ] + } + ], + "source": [ + "#They don't we can prove this by priting their shape\n", + "print(\"Shape of a:\", a.shape)\n", + "print(\"Shape of b:\", b.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(5, 2, 3)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "b.shape" ] }, { @@ -143,11 +248,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ - "# your answer here" + "#No, they have different shapes so they cannot be added." ] }, { @@ -159,11 +264,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(2, 3, 5)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "c = np.transpose(b, axes=(1, 2, 0))\n", + "c.shape" ] }, { @@ -175,11 +292,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ - "# your code/answer here" + "d = a + c\n", + "#it works now because they have the same shape." ] }, { @@ -191,11 +309,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0 7 4 4 3]\n", + " [1 1 7 2 0]\n", + " [7 1 9 5 0]]\n", + "\n", + " [[3 1 8 1 4]\n", + " [2 3 6 6 4]\n", + " [6 3 6 2 6]]]\n", + "[[[ 1. 8. 5. 5. 4.]\n", + " [ 2. 2. 8. 3. 1.]\n", + " [ 8. 2. 10. 6. 1.]]\n", + "\n", + " [[ 4. 2. 9. 2. 5.]\n", + " [ 3. 4. 7. 7. 5.]\n", + " [ 7. 4. 7. 3. 7.]]]\n" + ] + } + ], + "source": [ + "print(a)\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ - "# your code/answer here" + "# They have the same shape but different values" ] }, { @@ -207,11 +356,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0. 7. 4. 4. 3.]\n", + " [1. 1. 7. 2. 0.]\n", + " [7. 1. 9. 5. 0.]]\n", + "\n", + " [[3. 1. 8. 1. 4.]\n", + " [2. 3. 6. 6. 4.]\n", + " [6. 3. 6. 2. 6.]]]\n" + ] + } + ], "source": [ - "# your code here" + "e = a*c\n", + "print(e)" ] }, { @@ -223,11 +387,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ - "# your code/answer here" + "print(np.array_equal(a, e)) \n", + "#e is equal to a multiplied by an array of all ones, which is just a itself.\n", + "#also because the thing above says so.\n" ] }, { @@ -239,11 +413,27 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10.0\n", + "1.0\n", + "4.733333333333333\n" + ] + } + ], + "source": [ + "d_max = np.max(d)\n", + "d_min = np.min(d)\n", + "d_mean = np.mean(d)\n", + "\n", + "print(np.amax(d))\n", + "print(np.amin(d))\n", + "print(np.mean(d))" ] }, { @@ -255,11 +445,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Shape of f: (2, 3, 5)\n" + ] + } + ], + "source": [ + "f = np.empty(d.shape)\n", + "\n", + "print(\"Shape of f:\", f.shape)" ] }, { @@ -275,11 +475,39 @@ }, { "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ 0. 75. 75. 75. 25.]\n", + " [ 25. 25. 75. 25. 0.]\n", + " [ 75. 25. 100. 75. 0.]]\n", + "\n", + " [[ 25. 25. 75. 25. 75.]\n", + " [ 25. 25. 75. 75. 75.]\n", + " [ 75. 25. 75. 25. 75.]]]\n" + ] + } + ], + "source": [ + "for i in range(d.shape[0]):\n", + " for j in range(d.shape[1]):\n", + " for k in range(d.shape[2]):\n", + " if d[i,j,k] == d_min:\n", + " f[i,j,k] = 0\n", + " elif d_min < d[i,j,k] < d_mean:\n", + " f[i,j,k] = 25\n", + " elif d[i,j,k] == d_mean:\n", + " f[i,j,k] = 50\n", + " elif d_mean < d[i,j,k] < d_max:\n", + " f[i,j,k] = 75\n", + " elif d[i,j,k] == d_max:\n", + " f[i,j,k] = 100\n", + "\n", + "print(f)" ] }, { @@ -309,11 +537,33 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ 1. 8. 5. 5. 4.]\n", + " [ 2. 2. 8. 3. 1.]\n", + " [ 8. 2. 10. 6. 1.]]\n", + "\n", + " [[ 4. 2. 9. 2. 5.]\n", + " [ 3. 4. 7. 7. 5.]\n", + " [ 7. 4. 7. 3. 7.]]]\n", + "[[[ 0. 75. 75. 75. 25.]\n", + " [ 25. 25. 75. 25. 0.]\n", + " [ 75. 25. 100. 75. 0.]]\n", + "\n", + " [[ 25. 25. 75. 25. 75.]\n", + " [ 25. 25. 75. 75. 75.]\n", + " [ 75. 25. 75. 25. 75.]]]\n" + ] + } + ], + "source": [ + "print(d)\n", + "print(f)" ] }, { @@ -333,14 +583,61 @@ "**Note**: you don't have to use Numpy in this question." ] }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "d:\n", + " [[[ 1. 8. 5. 5. 4.]\n", + " [ 2. 2. 8. 3. 1.]\n", + " [ 8. 2. 10. 6. 1.]]\n", + "\n", + " [[ 4. 2. 9. 2. 5.]\n", + " [ 3. 4. 7. 7. 5.]\n", + " [ 7. 4. 7. 3. 7.]]]\n", + "f:\n", + " [[['A' 'D' 'D' 'D' 'B']\n", + " ['B' 'B' 'D' 'B' 'A']\n", + " ['D' 'B' 'E' 'D' 'A']]\n", + "\n", + " [['B' 'B' 'D' 'B' 'D']\n", + " ['B' 'B' 'D' 'D' 'D']\n", + " ['D' 'B' 'D' 'B' 'D']]]\n" + ] + } + ], + "source": [ + "f = np.empty_like(d, dtype='U1')\n", + "\n", + "for i in range(d.shape[0]):\n", + " for j in range(d.shape[1]):\n", + " for k in range(d.shape[2]):\n", + " if d[i,j,k] > d_min and d[i,j,k] < d_mean:\n", + " f[i,j,k] = \"B\"\n", + " elif d[i,j,k] > d_mean and d[i,j,k] < d_max:\n", + " f[i,j,k] = \"D\"\n", + " elif d[i,j,k] == d_mean:\n", + " f[i,j,k] = \"C\"\n", + " elif d[i,j,k] == d_min:\n", + " f[i,j,k] = \"A\"\n", + " elif d[i,j,k] == d_max:\n", + " f[i,j,k] = \"E\"\n", + "\n", + "print(\"d:\\n\", d)\n", + "print(\"f:\\n\", f)" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "# your code here" - ] + "source": [] } ], "metadata": { @@ -359,7 +656,12 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.10.7" + }, + "vscode": { + "interpreter": { + "hash": "721db305ef1fd1fc91cdf20e400af694a949fe540ac5f48c160f31c7e384879d" + } } }, "nbformat": 4,