diff --git a/your-code/.ipynb_checkpoints/lab_numpy-checkpoint.ipynb b/your-code/.ipynb_checkpoints/lab_numpy-checkpoint.ipynb new file mode 100644 index 0000000..5707fcd --- /dev/null +++ b/your-code/.ipynb_checkpoints/lab_numpy-checkpoint.ipynb @@ -0,0 +1,694 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#1. Import the NUMPY package under the name np.\n", + "\n", + "\n", + "\n", + "#2. Print the NUMPY version and the configuration.\n", + "\n", + "\n", + "\n", + "#3. Generate a 2x3x5 3-dimensional array with random values. Assign the array to variable \"a\"\n", + "# Challenge: there are at least three easy ways that use numpy to generate random arrays. How many ways can you find?\n", + "\n", + "\n", + "\n", + "#4. Print a.\n", + "\n", + "\n", + "\n", + "#5. Create a 5x2x3 3-dimensional array with all values equaling 1.\n", + "#Assign the array to variable \"b\"\n", + "\n", + "\n", + "\n", + "#6. Print b.\n", + "\n", + "\n", + "\n", + "#7. Do a and b have the same size? How do you prove that in Python code?\n", + "\n", + "\n", + "\n", + "\n", + "#8. Are you able to add a and b? Why or why not?\n", + "\n", + "\n", + "\n", + "#9. Transpose b so that it has the same structure of a (i.e. become a 2x3x5 array). Assign the transposed array to varialbe \"c\".\n", + "\n", + "\n", + "\n", + "#10. Try to add a and c. Now it should work. Assign the sum to varialbe \"d\". But why does it work now?\n", + "\n", + "\n", + "\n", + "#11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain.\n", + "\n", + "\n", + "\n", + "\n", + "#12. Multiply a and c. Assign the result to e.\n", + "\n", + "\n", + "\n", + "#13. Does e equal to a? Why or why not?\n", + "\n", + "\n", + "\n", + "\n", + "#14. Identify the max, min, and mean values in d. Assign those values to variables \"d_max\", \"d_min\", and \"d_mean\"\n", + "\n", + "\n", + "\n", + "\n", + "#15. Now we want to label the values in d. First create an empty array \"f\" with the same shape (i.e. 2x3x5) as d using `np.empty`.\n", + "\n", + "\n", + "\n", + "\n", + "\"\"\"\n", + "#16. Populate the values in f. For each value in d, if it's larger than d_min but smaller than d_mean, assign 25 to the corresponding value in f.\n", + "If a value in d is larger than d_mean but smaller than d_max, assign 75 to the corresponding value in f.\n", + "If a value equals to d_mean, assign 50 to the corresponding value in f.\n", + "Assign 0 to the corresponding value(s) in f for d_min in d.\n", + "Assign 100 to the corresponding value(s) in f for d_max in d.\n", + "In the end, f should have only the following values: 0, 25, 50, 75, and 100.\n", + "Note: you don't have to use Numpy in this question.\n", + "\"\"\"\n", + "\n", + "\n", + "\n", + "\n", + "\"\"\"\n", + "#17. Print d and f. Do you have your expected f?\n", + "For instance, if your d is:\n", + "array([[[1.85836099, 1.67064465, 1.62576044, 1.40243961, 1.88454931],\n", + " [1.75354326, 1.69403643, 1.36729252, 1.61415071, 1.12104981],\n", + " [1.72201435, 1.1862918 , 1.87078449, 1.7726778 , 1.88180042]],\n", + "\n", + " [[1.44747908, 1.31673383, 1.02000951, 1.52218947, 1.97066381],\n", + " [1.79129243, 1.74983003, 1.96028037, 1.85166831, 1.65450881],\n", + " [1.18068344, 1.9587381 , 1.00656599, 1.93402165, 1.73514584]]])\n", + "\n", + "Your f should be:\n", + "array([[[ 75., 75., 75., 25., 75.],\n", + " [ 75., 75., 25., 25., 25.],\n", + " [ 75., 25., 75., 75., 75.]],\n", + "\n", + " [[ 25., 25., 25., 25., 100.],\n", + " [ 75., 75., 75., 75., 75.],\n", + " [ 25., 75., 0., 75., 75.]]])\n", + "\"\"\"\n", + "\n", + "\n", + "\"\"\"\n", + "#18. Bonus question: instead of using numbers (i.e. 0, 25, 50, 75, and 100), how to use string values \n", + "(\"A\", \"B\", \"C\", \"D\", and \"E\") to label the array elements? You are expecting the result to be:\n", + "array([[[ 'D', 'D', 'D', 'B', 'D'],\n", + " [ 'D', 'D', 'B', 'B', 'B'],\n", + " [ 'D', 'B', 'D', 'D', 'D']],\n", + "\n", + " [[ 'B', 'B', 'B', 'B', 'E'],\n", + " [ 'D', 'D', 'D', 'D', 'D'],\n", + " [ 'B', 'D', 'A', 'D', 'D']]])\n", + "Again, you don't need Numpy in this question.\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#1. Import the NUMPY package under the name np.\n", + "import numpy as np\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'1.16.5'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#2. Print the NUMPY version and the configuration.\n", + "np.__version__" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.68715127 0.82406254 0.01507663 0.23298695 0.15778438]\n", + " [0.74029022 0.74974046 0.51710675 0.24782055 0.10697461]\n", + " [0.21152137 0.00535034 0.60328346 0.76696918 0.94201888]]\n", + "\n", + " [[0.8499052 0.92773377 0.61834944 0.63715533 0.23015513]\n", + " [0.48996901 0.59130385 0.20200726 0.22436965 0.64781637]\n", + " [0.41480577 0.48413731 0.96185469 0.14643907 0.5722567 ]]]\n" + ] + } + ], + "source": [ + "#3. Generate a 2x3x5 3-dimensional array with random values. Assign the array to variable \"a\"\n", + "\n", + "a = np.random.random((2,3,5))\n", + "#4. Print a.\n", + "print(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "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": [ + "#5. Create a 5x2x3 3-dimensional array with all values equaling 1.\n", + "\n", + "b = np.ones((5,2,3))\n", + "\n", + "#Assign the array to variable \"b\"\n", + "\n", + "print(b)\n", + "\n", + "#6. Print b." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(True, 30, 30)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#7. Do a and b have the same size? How do you prove that in Python code?\n", + "\n", + "a.size == b.size, a.size,b.size" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "operands could not be broadcast together with shapes (2,3,5) (5,2,3) ", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m#8. Are you able to add a and b? Why or why not?\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# No es posible porque tiene shapes diferentes\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3,5) (5,2,3) " + ] + } + ], + "source": [ + "#8. Are you able to add a and b? Why or why not?\n", + "np.add(a,b) # No es posible porque tiene shapes diferentes" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[1., 1., 1., 1., 1.],\n", + " [1., 1., 1., 1., 1.],\n", + " [1., 1., 1., 1., 1.]],\n", + "\n", + " [[1., 1., 1., 1., 1.],\n", + " [1., 1., 1., 1., 1.],\n", + " [1., 1., 1., 1., 1.]]])" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#9. Transpose b so that it has the same structure of a (i.e. become a 2x3x5 array). Assign the transposed array to varialbe \"c\".\n", + "c = b.reshape(2,3,5)\n", + "c" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[2.53705647, 2.75179631, 1.63342607, 1.87014228, 1.38793951],\n", + " [2.23025923, 2.34104431, 1.71911401, 1.4721902 , 1.75479098],\n", + " [1.62632715, 1.48948765, 2.56513815, 1.91340824, 2.51427558]],\n", + "\n", + " [[2.53705647, 2.75179631, 1.63342607, 1.87014228, 1.38793951],\n", + " [2.23025923, 2.34104431, 1.71911401, 1.4721902 , 1.75479098],\n", + " [1.62632715, 1.48948765, 2.56513815, 1.91340824, 2.51427558]]])" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#10. Try to add a and c. Now it should work. Assign the sum to varialbe \"d\". But why does it work now?\n", + "d = sum(a,c)\n", + "d\n", + "# Funciona porque las shapes son iguales en este caso" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.68715127 0.82406254 0.01507663 0.23298695 0.15778438]\n", + " [0.74029022 0.74974046 0.51710675 0.24782055 0.10697461]\n", + " [0.21152137 0.00535034 0.60328346 0.76696918 0.94201888]]\n", + "\n", + " [[0.8499052 0.92773377 0.61834944 0.63715533 0.23015513]\n", + " [0.48996901 0.59130385 0.20200726 0.22436965 0.64781637]\n", + " [0.41480577 0.48413731 0.96185469 0.14643907 0.5722567 ]]]\n", + "\n", + "\n", + "\n", + "[[[2.53705647 2.75179631 1.63342607 1.87014228 1.38793951]\n", + " [2.23025923 2.34104431 1.71911401 1.4721902 1.75479098]\n", + " [1.62632715 1.48948765 2.56513815 1.91340824 2.51427558]]\n", + "\n", + " [[2.53705647 2.75179631 1.63342607 1.87014228 1.38793951]\n", + " [2.23025923 2.34104431 1.71911401 1.4721902 1.75479098]\n", + " [1.62632715 1.48948765 2.56513815 1.91340824 2.51427558]]]\n" + ] + } + ], + "source": [ + "#11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain.\n", + "print(a,end=\"\\n\\n\\n\\n\")\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[0.68715127, 0.82406254, 0.01507663, 0.23298695, 0.15778438],\n", + " [0.74029022, 0.74974046, 0.51710675, 0.24782055, 0.10697461],\n", + " [0.21152137, 0.00535034, 0.60328346, 0.76696918, 0.94201888]],\n", + "\n", + " [[0.8499052 , 0.92773377, 0.61834944, 0.63715533, 0.23015513],\n", + " [0.48996901, 0.59130385, 0.20200726, 0.22436965, 0.64781637],\n", + " [0.41480577, 0.48413731, 0.96185469, 0.14643907, 0.5722567 ]]])" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#12. Multiply a and c. Assign the result to e.\n", + "\n", + "e = np.multiply(a,c)\n", + "e" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#13. Does e equal to a? Why or why not?\n", + "#Si porque C se esta multiplicando por 1" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "d_max = 2.7517963077043226, d_min = 1.3879395138783137, d_mean = 1.9870930760796879\n" + ] + } + ], + "source": [ + "#14. Identify the max, min, and mean values in d. \n", + "#Assign those values to variables \"d_max\", \"d_min\", and \"d_mean\"\n", + "d_max, d_min, d_mean = d.max(), d.min(), d.mean()\n", + "\n", + "print(\"d_max = {}, d_min = {}, d_mean = {}\".format(d_max, d_min, d_mean))" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "primer nivel -> 0 [[0.68715127 0.82406254 0.01507663 0.23298695 0.15778438]\n", + " [0.74029022 0.74974046 0.51710675 0.24782055 0.10697461]\n", + " [0.21152137 0.00535034 0.60328346 0.76696918 0.94201888]]\n", + "segundo nivel-> 0 [0.68715127 0.82406254 0.01507663 0.23298695 0.15778438]\n", + "tecer nivel -> 0 0.6871512700101372\n", + "tecer nivel -> 1 0.8240625368616495\n", + "tecer nivel -> 2 0.015076633250311833\n", + "tecer nivel -> 3 0.23298695055165264\n", + "tecer nivel -> 4 0.15778437990201244\n", + "segundo nivel-> 1 [0.74029022 0.74974046 0.51710675 0.24782055 0.10697461]\n", + "tecer nivel -> 0 0.740290218238114\n", + "tecer nivel -> 1 0.7497404618586336\n", + "tecer nivel -> 2 0.517106750611566\n", + "tecer nivel -> 3 0.24782054786032648\n", + "tecer nivel -> 4 0.10697461356456417\n", + "segundo nivel-> 2 [0.21152137 0.00535034 0.60328346 0.76696918 0.94201888]\n", + "tecer nivel -> 0 0.2115213749129108\n", + "tecer nivel -> 1 0.005350336674465939\n", + "tecer nivel -> 2 0.6032834614904741\n", + "tecer nivel -> 3 0.7669691778235445\n", + "tecer nivel -> 4 0.9420188785562479\n", + "primer nivel -> 1 [[0.8499052 0.92773377 0.61834944 0.63715533 0.23015513]\n", + " [0.48996901 0.59130385 0.20200726 0.22436965 0.64781637]\n", + " [0.41480577 0.48413731 0.96185469 0.14643907 0.5722567 ]]\n", + "segundo nivel-> 0 [0.8499052 0.92773377 0.61834944 0.63715533 0.23015513]\n", + "tecer nivel -> 0 0.8499051968467961\n", + "tecer nivel -> 1 0.9277337708426731\n", + "tecer nivel -> 2 0.6183494387561023\n", + "tecer nivel -> 3 0.6371553309210428\n", + "tecer nivel -> 4 0.23015513397630127\n", + "segundo nivel-> 1 [0.48996901 0.59130385 0.20200726 0.22436965 0.64781637]\n", + "tecer nivel -> 0 0.4899690080519531\n", + "tecer nivel -> 1 0.5913038523605847\n", + "tecer nivel -> 2 0.20200726022311488\n", + "tecer nivel -> 3 0.22436965474447057\n", + "tecer nivel -> 4 0.6478163680586465\n", + "segundo nivel-> 2 [0.41480577 0.48413731 0.96185469 0.14643907 0.5722567 ]\n", + "tecer nivel -> 0 0.41480577358571147\n", + "tecer nivel -> 1 0.48413731203188226\n", + "tecer nivel -> 2 0.961854686378675\n", + "tecer nivel -> 3 0.1464390651024251\n", + "tecer nivel -> 4 0.5722566971483235\n" + ] + } + ], + "source": [ + "#15. Now we want to label the values in d. \n", + "#First create an empty array \"f\" with the same shape (i.e. 2x3x5) as d using np.empty.\n", + "\n", + "f = np.empty([2,3,5])\n", + "\n", + "for i,j in enumerate(f):\n", + " print(\"primer nivel -> {} {}\".format(i,j))\n", + " for x,k in enumerate(j):\n", + " print(\"segundo nivel-> {} {}\".format(x,k))\n", + " for counter,valor in enumerate(k):\n", + " print(\"tecer nivel -> {} {}\".format(counter, valor))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "#16. Populate the values in f. For each value in d, if it's larger than d_min but smaller than d_mean, \n", + "# assign 25 to the corresponding value in f. If a value in d is larger than d_mean but smaller than d_max,\n", + "#assign 75 to the corresponding value in f. If a value equals to d_mean, \n", + "#assign 50 to the corresponding value in f. Assign 0 to the corresponding value(s) in f for d_min in d. \n", + "#Assign 100 to the corresponding value(s) in f for d_max in d. \n", + "#In the end, f should have only the following values: 0, 25, 50, 75, and 100. \n", + "\n", + "\n", + "#for line in data_array:\n", + " # result = do_stuff(line)\n", + " # result_array = np.append(result_array, [result], axis=0)\n", + "\n", + "#3d array to list\n", + "#d2 = d.tolist()\n", + " \n", + "\n", + "for i,y in enumerate(d):\n", + " for j,x in enumerate(y):\n", + " for l,r in enumerate(x):\n", + " if r > d_min and r < d_mean: f[i][j][l] = 25\n", + " elif r > d_mean and r < d_max: f[i][j][l] = 75\n", + " elif r == d_mean:f[i][j][l] = 50\n", + " elif r == d_min: f[i][j][l] = 0\n", + " elif r == d_max: f[i][j][l] = 100\n", + " \n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[ 75., 100., 25., 25., 0.],\n", + " [ 75., 75., 25., 25., 25.],\n", + " [ 25., 25., 75., 25., 75.]],\n", + "\n", + " [[ 75., 100., 25., 25., 0.],\n", + " [ 75., 75., 25., 25., 25.],\n", + " [ 25., 25., 75., 25., 75.]]])" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[2.53705647 2.75179631 1.63342607 1.87014228 1.38793951]\n", + " [2.23025923 2.34104431 1.71911401 1.4721902 1.75479098]\n", + " [1.62632715 1.48948765 2.56513815 1.91340824 2.51427558]]\n", + "\n", + " [[2.53705647 2.75179631 1.63342607 1.87014228 1.38793951]\n", + " [2.23025923 2.34104431 1.71911401 1.4721902 1.75479098]\n", + " [1.62632715 1.48948765 2.56513815 1.91340824 2.51427558]]]\n", + "\n", + "\n", + "[[[ 75. 100. 25. 25. 0.]\n", + " [ 75. 75. 25. 25. 25.]\n", + " [ 25. 25. 75. 25. 75.]]\n", + "\n", + " [[ 75. 100. 25. 25. 0.]\n", + " [ 75. 75. 25. 25. 25.]\n", + " [ 25. 25. 75. 25. 75.]]]\n" + ] + } + ], + "source": [ + "#17. Print d and f. Do you have your expected f? For instance, \n", + "#if your d is: array([[[1.85836099, 1.67064465, 1.62576044, 1.40243961, 1.88454931], [1.75354326, 1.69403643, 1.36729252, 1.61415071, 1.12104981], [1.72201435, 1.1862918 , 1.87078449, 1.7726778 , 1.88180042]],\n", + "\n", + " #[[1.44747908, 1.31673383, 1.02000951, 1.52218947, 1.97066381],\n", + " #[1.79129243, 1.74983003, 1.96028037, 1.85166831, 1.65450881],\n", + " #[1.18068344, 1.9587381 , 1.00656599, 1.93402165, 1.73514584]]])\n", + "#Your f should be: array([[[ 75., 75., 75., 25., 75.], [ 75., 75., 25., 25., 25.], [ 75., 25., 75., 75., 75.]],\n", + "\n", + " # [[ 25., 25., 25., 25., 100.],\n", + " # [ 75., 75., 75., 75., 75.],\n", + " # [ 25., 75., 0., 75., 75.]]])\n", + " \n", + "print(d,end=\"\\n\\n\\n\")\n", + "print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#18. Bonus question: instead of using numbers (i.e. 0, 25, 50, 75, and 100), \n", + "#how to use string values (\"A\", \"B\", \"C\", \"D\", and \"E\") to label the array elements? \n", + "#You are expecting the result to be: array([[[ 'D', 'D', 'D', 'B', 'D'], [ 'D', 'D', 'B', 'B', 'B'], [ 'D', 'B', 'D', 'D', 'D']],\n", + "\n", + " # [[ 'B', 'B', 'B', 'B', 'E'],\n", + " # [ 'D', 'D', 'D', 'D', 'D'],\n", + " #[ 'B', 'D', 'A', 'D', 'D']]])\n", + "#Again, you don't need Numpy in this question." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "ff = np.empty([2,3,5], dtype=\"object\")" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "for i,y in enumerate(d):\n", + " for j,x in enumerate(y):\n", + " for l,r in enumerate(x):\n", + " if r > d_min and r < d_mean: ff[i][j][l] = \"B\"\n", + " elif r > d_mean and r < d_max: ff[i][j][l] = \"D\"\n", + " elif r == d_mean:ff[i][j][l] = \"C\"\n", + " elif r == d_min: ff[i][j][l] = \"A\"\n", + " elif r == d_max: ff[i][j][l] = \"E\"\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[['D', 'E', 'B', 'B', 'A'],\n", + " ['D', 'D', 'B', 'B', 'B'],\n", + " ['B', 'B', 'D', 'B', 'D']],\n", + "\n", + " [['D', 'E', 'B', 'B', 'A'],\n", + " ['D', 'D', 'B', 'B', 'B'],\n", + " ['B', 'B', 'D', 'B', 'D']]], dtype=object)" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ff" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/lab_numpy.ipynb b/your-code/lab_numpy.ipynb new file mode 100644 index 0000000..5707fcd --- /dev/null +++ b/your-code/lab_numpy.ipynb @@ -0,0 +1,694 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#1. Import the NUMPY package under the name np.\n", + "\n", + "\n", + "\n", + "#2. Print the NUMPY version and the configuration.\n", + "\n", + "\n", + "\n", + "#3. Generate a 2x3x5 3-dimensional array with random values. Assign the array to variable \"a\"\n", + "# Challenge: there are at least three easy ways that use numpy to generate random arrays. How many ways can you find?\n", + "\n", + "\n", + "\n", + "#4. Print a.\n", + "\n", + "\n", + "\n", + "#5. Create a 5x2x3 3-dimensional array with all values equaling 1.\n", + "#Assign the array to variable \"b\"\n", + "\n", + "\n", + "\n", + "#6. Print b.\n", + "\n", + "\n", + "\n", + "#7. Do a and b have the same size? How do you prove that in Python code?\n", + "\n", + "\n", + "\n", + "\n", + "#8. Are you able to add a and b? Why or why not?\n", + "\n", + "\n", + "\n", + "#9. Transpose b so that it has the same structure of a (i.e. become a 2x3x5 array). Assign the transposed array to varialbe \"c\".\n", + "\n", + "\n", + "\n", + "#10. Try to add a and c. Now it should work. Assign the sum to varialbe \"d\". But why does it work now?\n", + "\n", + "\n", + "\n", + "#11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain.\n", + "\n", + "\n", + "\n", + "\n", + "#12. Multiply a and c. Assign the result to e.\n", + "\n", + "\n", + "\n", + "#13. Does e equal to a? Why or why not?\n", + "\n", + "\n", + "\n", + "\n", + "#14. Identify the max, min, and mean values in d. Assign those values to variables \"d_max\", \"d_min\", and \"d_mean\"\n", + "\n", + "\n", + "\n", + "\n", + "#15. Now we want to label the values in d. First create an empty array \"f\" with the same shape (i.e. 2x3x5) as d using `np.empty`.\n", + "\n", + "\n", + "\n", + "\n", + "\"\"\"\n", + "#16. Populate the values in f. For each value in d, if it's larger than d_min but smaller than d_mean, assign 25 to the corresponding value in f.\n", + "If a value in d is larger than d_mean but smaller than d_max, assign 75 to the corresponding value in f.\n", + "If a value equals to d_mean, assign 50 to the corresponding value in f.\n", + "Assign 0 to the corresponding value(s) in f for d_min in d.\n", + "Assign 100 to the corresponding value(s) in f for d_max in d.\n", + "In the end, f should have only the following values: 0, 25, 50, 75, and 100.\n", + "Note: you don't have to use Numpy in this question.\n", + "\"\"\"\n", + "\n", + "\n", + "\n", + "\n", + "\"\"\"\n", + "#17. Print d and f. Do you have your expected f?\n", + "For instance, if your d is:\n", + "array([[[1.85836099, 1.67064465, 1.62576044, 1.40243961, 1.88454931],\n", + " [1.75354326, 1.69403643, 1.36729252, 1.61415071, 1.12104981],\n", + " [1.72201435, 1.1862918 , 1.87078449, 1.7726778 , 1.88180042]],\n", + "\n", + " [[1.44747908, 1.31673383, 1.02000951, 1.52218947, 1.97066381],\n", + " [1.79129243, 1.74983003, 1.96028037, 1.85166831, 1.65450881],\n", + " [1.18068344, 1.9587381 , 1.00656599, 1.93402165, 1.73514584]]])\n", + "\n", + "Your f should be:\n", + "array([[[ 75., 75., 75., 25., 75.],\n", + " [ 75., 75., 25., 25., 25.],\n", + " [ 75., 25., 75., 75., 75.]],\n", + "\n", + " [[ 25., 25., 25., 25., 100.],\n", + " [ 75., 75., 75., 75., 75.],\n", + " [ 25., 75., 0., 75., 75.]]])\n", + "\"\"\"\n", + "\n", + "\n", + "\"\"\"\n", + "#18. Bonus question: instead of using numbers (i.e. 0, 25, 50, 75, and 100), how to use string values \n", + "(\"A\", \"B\", \"C\", \"D\", and \"E\") to label the array elements? You are expecting the result to be:\n", + "array([[[ 'D', 'D', 'D', 'B', 'D'],\n", + " [ 'D', 'D', 'B', 'B', 'B'],\n", + " [ 'D', 'B', 'D', 'D', 'D']],\n", + "\n", + " [[ 'B', 'B', 'B', 'B', 'E'],\n", + " [ 'D', 'D', 'D', 'D', 'D'],\n", + " [ 'B', 'D', 'A', 'D', 'D']]])\n", + "Again, you don't need Numpy in this question.\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#1. Import the NUMPY package under the name np.\n", + "import numpy as np\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'1.16.5'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#2. Print the NUMPY version and the configuration.\n", + "np.__version__" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.68715127 0.82406254 0.01507663 0.23298695 0.15778438]\n", + " [0.74029022 0.74974046 0.51710675 0.24782055 0.10697461]\n", + " [0.21152137 0.00535034 0.60328346 0.76696918 0.94201888]]\n", + "\n", + " [[0.8499052 0.92773377 0.61834944 0.63715533 0.23015513]\n", + " [0.48996901 0.59130385 0.20200726 0.22436965 0.64781637]\n", + " [0.41480577 0.48413731 0.96185469 0.14643907 0.5722567 ]]]\n" + ] + } + ], + "source": [ + "#3. Generate a 2x3x5 3-dimensional array with random values. Assign the array to variable \"a\"\n", + "\n", + "a = np.random.random((2,3,5))\n", + "#4. Print a.\n", + "print(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "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": [ + "#5. Create a 5x2x3 3-dimensional array with all values equaling 1.\n", + "\n", + "b = np.ones((5,2,3))\n", + "\n", + "#Assign the array to variable \"b\"\n", + "\n", + "print(b)\n", + "\n", + "#6. Print b." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(True, 30, 30)" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#7. Do a and b have the same size? How do you prove that in Python code?\n", + "\n", + "a.size == b.size, a.size,b.size" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "operands could not be broadcast together with shapes (2,3,5) (5,2,3) ", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m#8. Are you able to add a and b? Why or why not?\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# No es posible porque tiene shapes diferentes\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3,5) (5,2,3) " + ] + } + ], + "source": [ + "#8. Are you able to add a and b? Why or why not?\n", + "np.add(a,b) # No es posible porque tiene shapes diferentes" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[1., 1., 1., 1., 1.],\n", + " [1., 1., 1., 1., 1.],\n", + " [1., 1., 1., 1., 1.]],\n", + "\n", + " [[1., 1., 1., 1., 1.],\n", + " [1., 1., 1., 1., 1.],\n", + " [1., 1., 1., 1., 1.]]])" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#9. Transpose b so that it has the same structure of a (i.e. become a 2x3x5 array). Assign the transposed array to varialbe \"c\".\n", + "c = b.reshape(2,3,5)\n", + "c" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[2.53705647, 2.75179631, 1.63342607, 1.87014228, 1.38793951],\n", + " [2.23025923, 2.34104431, 1.71911401, 1.4721902 , 1.75479098],\n", + " [1.62632715, 1.48948765, 2.56513815, 1.91340824, 2.51427558]],\n", + "\n", + " [[2.53705647, 2.75179631, 1.63342607, 1.87014228, 1.38793951],\n", + " [2.23025923, 2.34104431, 1.71911401, 1.4721902 , 1.75479098],\n", + " [1.62632715, 1.48948765, 2.56513815, 1.91340824, 2.51427558]]])" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#10. Try to add a and c. Now it should work. Assign the sum to varialbe \"d\". But why does it work now?\n", + "d = sum(a,c)\n", + "d\n", + "# Funciona porque las shapes son iguales en este caso" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.68715127 0.82406254 0.01507663 0.23298695 0.15778438]\n", + " [0.74029022 0.74974046 0.51710675 0.24782055 0.10697461]\n", + " [0.21152137 0.00535034 0.60328346 0.76696918 0.94201888]]\n", + "\n", + " [[0.8499052 0.92773377 0.61834944 0.63715533 0.23015513]\n", + " [0.48996901 0.59130385 0.20200726 0.22436965 0.64781637]\n", + " [0.41480577 0.48413731 0.96185469 0.14643907 0.5722567 ]]]\n", + "\n", + "\n", + "\n", + "[[[2.53705647 2.75179631 1.63342607 1.87014228 1.38793951]\n", + " [2.23025923 2.34104431 1.71911401 1.4721902 1.75479098]\n", + " [1.62632715 1.48948765 2.56513815 1.91340824 2.51427558]]\n", + "\n", + " [[2.53705647 2.75179631 1.63342607 1.87014228 1.38793951]\n", + " [2.23025923 2.34104431 1.71911401 1.4721902 1.75479098]\n", + " [1.62632715 1.48948765 2.56513815 1.91340824 2.51427558]]]\n" + ] + } + ], + "source": [ + "#11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain.\n", + "print(a,end=\"\\n\\n\\n\\n\")\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[0.68715127, 0.82406254, 0.01507663, 0.23298695, 0.15778438],\n", + " [0.74029022, 0.74974046, 0.51710675, 0.24782055, 0.10697461],\n", + " [0.21152137, 0.00535034, 0.60328346, 0.76696918, 0.94201888]],\n", + "\n", + " [[0.8499052 , 0.92773377, 0.61834944, 0.63715533, 0.23015513],\n", + " [0.48996901, 0.59130385, 0.20200726, 0.22436965, 0.64781637],\n", + " [0.41480577, 0.48413731, 0.96185469, 0.14643907, 0.5722567 ]]])" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#12. Multiply a and c. Assign the result to e.\n", + "\n", + "e = np.multiply(a,c)\n", + "e" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#13. Does e equal to a? Why or why not?\n", + "#Si porque C se esta multiplicando por 1" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "d_max = 2.7517963077043226, d_min = 1.3879395138783137, d_mean = 1.9870930760796879\n" + ] + } + ], + "source": [ + "#14. Identify the max, min, and mean values in d. \n", + "#Assign those values to variables \"d_max\", \"d_min\", and \"d_mean\"\n", + "d_max, d_min, d_mean = d.max(), d.min(), d.mean()\n", + "\n", + "print(\"d_max = {}, d_min = {}, d_mean = {}\".format(d_max, d_min, d_mean))" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "primer nivel -> 0 [[0.68715127 0.82406254 0.01507663 0.23298695 0.15778438]\n", + " [0.74029022 0.74974046 0.51710675 0.24782055 0.10697461]\n", + " [0.21152137 0.00535034 0.60328346 0.76696918 0.94201888]]\n", + "segundo nivel-> 0 [0.68715127 0.82406254 0.01507663 0.23298695 0.15778438]\n", + "tecer nivel -> 0 0.6871512700101372\n", + "tecer nivel -> 1 0.8240625368616495\n", + "tecer nivel -> 2 0.015076633250311833\n", + "tecer nivel -> 3 0.23298695055165264\n", + "tecer nivel -> 4 0.15778437990201244\n", + "segundo nivel-> 1 [0.74029022 0.74974046 0.51710675 0.24782055 0.10697461]\n", + "tecer nivel -> 0 0.740290218238114\n", + "tecer nivel -> 1 0.7497404618586336\n", + "tecer nivel -> 2 0.517106750611566\n", + "tecer nivel -> 3 0.24782054786032648\n", + "tecer nivel -> 4 0.10697461356456417\n", + "segundo nivel-> 2 [0.21152137 0.00535034 0.60328346 0.76696918 0.94201888]\n", + "tecer nivel -> 0 0.2115213749129108\n", + "tecer nivel -> 1 0.005350336674465939\n", + "tecer nivel -> 2 0.6032834614904741\n", + "tecer nivel -> 3 0.7669691778235445\n", + "tecer nivel -> 4 0.9420188785562479\n", + "primer nivel -> 1 [[0.8499052 0.92773377 0.61834944 0.63715533 0.23015513]\n", + " [0.48996901 0.59130385 0.20200726 0.22436965 0.64781637]\n", + " [0.41480577 0.48413731 0.96185469 0.14643907 0.5722567 ]]\n", + "segundo nivel-> 0 [0.8499052 0.92773377 0.61834944 0.63715533 0.23015513]\n", + "tecer nivel -> 0 0.8499051968467961\n", + "tecer nivel -> 1 0.9277337708426731\n", + "tecer nivel -> 2 0.6183494387561023\n", + "tecer nivel -> 3 0.6371553309210428\n", + "tecer nivel -> 4 0.23015513397630127\n", + "segundo nivel-> 1 [0.48996901 0.59130385 0.20200726 0.22436965 0.64781637]\n", + "tecer nivel -> 0 0.4899690080519531\n", + "tecer nivel -> 1 0.5913038523605847\n", + "tecer nivel -> 2 0.20200726022311488\n", + "tecer nivel -> 3 0.22436965474447057\n", + "tecer nivel -> 4 0.6478163680586465\n", + "segundo nivel-> 2 [0.41480577 0.48413731 0.96185469 0.14643907 0.5722567 ]\n", + "tecer nivel -> 0 0.41480577358571147\n", + "tecer nivel -> 1 0.48413731203188226\n", + "tecer nivel -> 2 0.961854686378675\n", + "tecer nivel -> 3 0.1464390651024251\n", + "tecer nivel -> 4 0.5722566971483235\n" + ] + } + ], + "source": [ + "#15. Now we want to label the values in d. \n", + "#First create an empty array \"f\" with the same shape (i.e. 2x3x5) as d using np.empty.\n", + "\n", + "f = np.empty([2,3,5])\n", + "\n", + "for i,j in enumerate(f):\n", + " print(\"primer nivel -> {} {}\".format(i,j))\n", + " for x,k in enumerate(j):\n", + " print(\"segundo nivel-> {} {}\".format(x,k))\n", + " for counter,valor in enumerate(k):\n", + " print(\"tecer nivel -> {} {}\".format(counter, valor))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "#16. Populate the values in f. For each value in d, if it's larger than d_min but smaller than d_mean, \n", + "# assign 25 to the corresponding value in f. If a value in d is larger than d_mean but smaller than d_max,\n", + "#assign 75 to the corresponding value in f. If a value equals to d_mean, \n", + "#assign 50 to the corresponding value in f. Assign 0 to the corresponding value(s) in f for d_min in d. \n", + "#Assign 100 to the corresponding value(s) in f for d_max in d. \n", + "#In the end, f should have only the following values: 0, 25, 50, 75, and 100. \n", + "\n", + "\n", + "#for line in data_array:\n", + " # result = do_stuff(line)\n", + " # result_array = np.append(result_array, [result], axis=0)\n", + "\n", + "#3d array to list\n", + "#d2 = d.tolist()\n", + " \n", + "\n", + "for i,y in enumerate(d):\n", + " for j,x in enumerate(y):\n", + " for l,r in enumerate(x):\n", + " if r > d_min and r < d_mean: f[i][j][l] = 25\n", + " elif r > d_mean and r < d_max: f[i][j][l] = 75\n", + " elif r == d_mean:f[i][j][l] = 50\n", + " elif r == d_min: f[i][j][l] = 0\n", + " elif r == d_max: f[i][j][l] = 100\n", + " \n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[ 75., 100., 25., 25., 0.],\n", + " [ 75., 75., 25., 25., 25.],\n", + " [ 25., 25., 75., 25., 75.]],\n", + "\n", + " [[ 75., 100., 25., 25., 0.],\n", + " [ 75., 75., 25., 25., 25.],\n", + " [ 25., 25., 75., 25., 75.]]])" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[2.53705647 2.75179631 1.63342607 1.87014228 1.38793951]\n", + " [2.23025923 2.34104431 1.71911401 1.4721902 1.75479098]\n", + " [1.62632715 1.48948765 2.56513815 1.91340824 2.51427558]]\n", + "\n", + " [[2.53705647 2.75179631 1.63342607 1.87014228 1.38793951]\n", + " [2.23025923 2.34104431 1.71911401 1.4721902 1.75479098]\n", + " [1.62632715 1.48948765 2.56513815 1.91340824 2.51427558]]]\n", + "\n", + "\n", + "[[[ 75. 100. 25. 25. 0.]\n", + " [ 75. 75. 25. 25. 25.]\n", + " [ 25. 25. 75. 25. 75.]]\n", + "\n", + " [[ 75. 100. 25. 25. 0.]\n", + " [ 75. 75. 25. 25. 25.]\n", + " [ 25. 25. 75. 25. 75.]]]\n" + ] + } + ], + "source": [ + "#17. Print d and f. Do you have your expected f? For instance, \n", + "#if your d is: array([[[1.85836099, 1.67064465, 1.62576044, 1.40243961, 1.88454931], [1.75354326, 1.69403643, 1.36729252, 1.61415071, 1.12104981], [1.72201435, 1.1862918 , 1.87078449, 1.7726778 , 1.88180042]],\n", + "\n", + " #[[1.44747908, 1.31673383, 1.02000951, 1.52218947, 1.97066381],\n", + " #[1.79129243, 1.74983003, 1.96028037, 1.85166831, 1.65450881],\n", + " #[1.18068344, 1.9587381 , 1.00656599, 1.93402165, 1.73514584]]])\n", + "#Your f should be: array([[[ 75., 75., 75., 25., 75.], [ 75., 75., 25., 25., 25.], [ 75., 25., 75., 75., 75.]],\n", + "\n", + " # [[ 25., 25., 25., 25., 100.],\n", + " # [ 75., 75., 75., 75., 75.],\n", + " # [ 25., 75., 0., 75., 75.]]])\n", + " \n", + "print(d,end=\"\\n\\n\\n\")\n", + "print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#18. Bonus question: instead of using numbers (i.e. 0, 25, 50, 75, and 100), \n", + "#how to use string values (\"A\", \"B\", \"C\", \"D\", and \"E\") to label the array elements? \n", + "#You are expecting the result to be: array([[[ 'D', 'D', 'D', 'B', 'D'], [ 'D', 'D', 'B', 'B', 'B'], [ 'D', 'B', 'D', 'D', 'D']],\n", + "\n", + " # [[ 'B', 'B', 'B', 'B', 'E'],\n", + " # [ 'D', 'D', 'D', 'D', 'D'],\n", + " #[ 'B', 'D', 'A', 'D', 'D']]])\n", + "#Again, you don't need Numpy in this question." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "ff = np.empty([2,3,5], dtype=\"object\")" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "for i,y in enumerate(d):\n", + " for j,x in enumerate(y):\n", + " for l,r in enumerate(x):\n", + " if r > d_min and r < d_mean: ff[i][j][l] = \"B\"\n", + " elif r > d_mean and r < d_max: ff[i][j][l] = \"D\"\n", + " elif r == d_mean:ff[i][j][l] = \"C\"\n", + " elif r == d_min: ff[i][j][l] = \"A\"\n", + " elif r == d_max: ff[i][j][l] = \"E\"\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[['D', 'E', 'B', 'B', 'A'],\n", + " ['D', 'D', 'B', 'B', 'B'],\n", + " ['B', 'B', 'D', 'B', 'D']],\n", + "\n", + " [['D', 'E', 'B', 'B', 'A'],\n", + " ['D', 'D', 'B', 'B', 'B'],\n", + " ['B', 'B', 'D', 'B', 'D']]], dtype=object)" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ff" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/untitled b/your-code/untitled new file mode 100644 index 0000000..e69de29