diff --git a/README.md b/README.md index 9bd714a..f23c6b1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Ironhack Logo # Lab | Numpy Deep Dive - +hello ## Introduction An important ability of a data scientist/data engineer is to know where and how to find information that helps you to accomplish your work. In the exercise, you will both practice the Numpy features we discussed in the lesson and learn new features by looking up documentations and references. You will work on your own but remember the teaching staff is at your service whenever you encounter problems. diff --git a/your-code/main.ipynb b/your-code/main.ipynb index e66d6ce..e3e7ab1 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -12,11 +12,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "import numpy as np" ] }, { @@ -28,11 +29,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.24.2\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "print(np. __version__)" ] }, { @@ -45,29 +55,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "# Method 1" + "# Method 1\n", + "a = np.random.rand(2,3,5)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "# Method 2" + "# Method 2\n", + "\n", + "a = np.random.randn(2,3,5)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ - "# Method 3" + "# Method 3\n", + "\n", + "a = np.random.randint(10000,size = (2,3,5))" ] }, { @@ -79,11 +94,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[8403, 5316, 6339, 1936, 6078],\n", + " [ 768, 5510, 5795, 8321, 6965],\n", + " [7672, 2741, 5836, 4365, 6080]],\n", + "\n", + " [[6036, 2325, 8478, 9486, 5833],\n", + " [5138, 6564, 903, 1669, 6675],\n", + " [6281, 2941, 7059, 1718, 4671]]])" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# your code here\n", + "a" ] }, { @@ -95,11 +128,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "b = np.ones(shape = (5,3,2), dtype = int)\n" ] }, { @@ -111,11 +145,41 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[1, 1],\n", + " [1, 1],\n", + " [1, 1]],\n", + "\n", + " [[1, 1],\n", + " [1, 1],\n", + " [1, 1]],\n", + "\n", + " [[1, 1],\n", + " [1, 1],\n", + " [1, 1]],\n", + "\n", + " [[1, 1],\n", + " [1, 1],\n", + " [1, 1]],\n", + "\n", + " [[1, 1],\n", + " [1, 1],\n", + " [1, 1]]])" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# your code here\n", + "b" ] }, { @@ -127,11 +191,33 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(2, 3, 5)\n", + "(5, 3, 2)\n" + ] + }, + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# your code here\n", + "print(a.shape)\n", + "print(b.shape)\n", + "a.shape == b.shape" ] }, { @@ -143,11 +229,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ValueError", + "evalue": "operands could not be broadcast together with shapes (2,3,5) (5,3,2) ", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[22], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[39m# your answer here\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m a\u001b[39m+\u001b[39;49mb\n\u001b[0;32m 3\u001b[0m \u001b[39m# I am not able because they are not the same shape\u001b[39;00m\n", + "\u001b[1;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3,5) (5,3,2) " + ] + } + ], "source": [ - "# your answer here" + "# your answer here\n", + "a+b\n", + "# I am not able because they are not the same shape" ] }, { @@ -159,11 +259,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "(2, 3, 5)" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "c = b.transpose()\n", + "c.shape" ] }, { @@ -175,11 +288,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ - "# your code/answer here" + "# your code/answer here\n", + "\n", + "d = a + c\n", + "# it works now becasue by transposing the variable b it takes the same shape as a" ] }, { @@ -191,11 +307,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code/answer here" + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[3221 8546 9378 7381 4049]\n", + " [7038 3329 3378 3678 7633]\n", + " [4890 9752 9094 4658 618]]\n", + "\n", + " [[9733 6700 8506 4661 5699]\n", + " [4845 7634 4554 2434 4385]\n", + " [8437 872 8551 155 8608]]]\n", + "[[[3222 8547 9379 7382 4050]\n", + " [7039 3330 3379 3679 7634]\n", + " [4891 9753 9095 4659 619]]\n", + "\n", + " [[9734 6701 8507 4662 5700]\n", + " [4846 7635 4555 2435 4386]\n", + " [8438 873 8552 156 8609]]]\n" + ] + } + ], + "source": [ + "# your code/answer here\n", + "print(a)\n", + "print(d)\n", + "\n", + "# the values of d are plus 1 the values of a because of the addiction o a and c" ] }, { @@ -207,11 +348,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "\n", + "e = a*c" ] }, { @@ -225,9 +368,31 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], - "source": [ - "# your code/answer here" + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[ True, True, True, True, True],\n", + " [ True, True, True, True, True]],\n", + "\n", + " [[ True, True, True, True, True],\n", + " [ True, True, True, True, True]],\n", + "\n", + " [[ True, True, True, True, True],\n", + " [ True, True, True, True, True]]])" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# your code/answer here\n", + "\n", + "e == a\n", + "\n", + "# a equals to e becasue a value times 1 is always the value" ] }, { @@ -239,11 +404,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "156" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "d_max = np.max(d)\n", + "d_min = np.min(d)\n", + "d_mean =np.mean(d)\n" ] }, { @@ -255,11 +434,36 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[-0.90125632, -0.49884927, 0.67843865, 0.44780927,\n", + " 1.43855835],\n", + " [-0.25272754, -0.39347233, -0.13074275, 0.68259649,\n", + " -0.64556267],\n", + " [ 0.73851437, -0.54868685, 0.47604965, -1.03821367,\n", + " -0.17148502]],\n", + "\n", + " [[-1.07091061, 0.43254853, 1.00275267, 0.66797931,\n", + " -0.30161907],\n", + " [ 0.88236507, 2.03968168, 0.18384814, 0.26181123,\n", + " -1.64071659],\n", + " [ 1.137504 , 0.44397436, 0.8348345 , -0.35858541,\n", + " -0.35941937]]])" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# your code here\n", + "f = np.empty(d.shape)\n", + "f" ] }, { @@ -275,11 +479,25 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "\n", + "for item in range(f.shape[0]):\n", + " for item2 in range(f.shape[1]):\n", + " for item3 in range(f.shape[2]):\n", + " if d[item ][item2][item3] > d_min and d[item ][item2][item3] < d_mean:\n", + " f[item ][item2][item3] = 25\n", + " elif d[item ][item2][item3]< d_max and d[item ][item2][item3] > d_mean:\n", + " f[item ][item2][item3] = 75\n", + " elif d[item ][item2][item3] == d_mean:\n", + " f[item ][item2][item3] = 50\n", + " elif d[item ][item2][item3] == d_min:\n", + " f[item ][item2][item3] = 0\n", + " else:\n", + " f[item ][item2][item3] = 100" ] }, { @@ -309,11 +527,29 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[ 25., 75., 75., 75., 25.],\n", + " [ 75., 25., 25., 25., 75.],\n", + " [ 25., 100., 75., 25., 25.]],\n", + "\n", + " [[ 75., 75., 75., 25., 25.],\n", + " [ 25., 75., 25., 25., 25.],\n", + " [ 75., 25., 75., 0., 75.]]])" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# your code here\n", + "f" ] }, { @@ -335,9 +571,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "'<' not supported between instances of 'numpy.ndarray' and 'str'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[35], line 6\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[39mfor\u001b[39;00m item2 \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(f\u001b[39m.\u001b[39mshape[\u001b[39m1\u001b[39m]):\n\u001b[0;32m 5\u001b[0m \u001b[39mfor\u001b[39;00m item3 \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(f\u001b[39m.\u001b[39mshape[\u001b[39m2\u001b[39m]):\n\u001b[1;32m----> 6\u001b[0m \u001b[39mif\u001b[39;00m d[item ][item2][item3] \u001b[39m>\u001b[39;49m d_min \u001b[39mand\u001b[39;00m d[item ][item2][item3] \u001b[39m<\u001b[39m d_mean:\n\u001b[0;32m 7\u001b[0m f[item ][item2][item3] \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mB\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 8\u001b[0m \u001b[39melif\u001b[39;00m d[item ][item2][item3]\u001b[39m<\u001b[39m d_max \u001b[39mand\u001b[39;00m d[item ][item2][item3] \u001b[39m>\u001b[39m d_mean:\n", + "\u001b[1;31mTypeError\u001b[0m: '<' not supported between instances of 'numpy.ndarray' and 'str'" + ] + } + ], "source": [ "# your code here" ] @@ -359,7 +607,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.11.2" } }, "nbformat": 4,