From d95f23b6365d7c62e1c8d8ee051add58a5901ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20P=C3=A9rez=20Ortega?= Date: Mon, 5 Jul 2021 00:23:01 -0500 Subject: [PATCH 1/2] Lab terminado --- .DS_Store | Bin 0 -> 6148 bytes .../.ipynb_checkpoints/main-checkpoint.ipynb | 590 ++++++++++++++++++ your-code/main.ipynb | 590 ++++++++++++++++++ your-code/main.py | 1 - 4 files changed, 1180 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 your-code/.ipynb_checkpoints/main-checkpoint.ipynb create mode 100644 your-code/main.ipynb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..faa5bafd21c777e698b9711813e385dd8bb1d8db GIT binary patch literal 6148 zcmeHK-AWrl6h0GUI~x&mA=Jyc5xj^cskRCtY}0s=3qf457g}`J4RvANkz~_g)0BOU z_6>X#pTNgy&zYHsA(q~$$T@K4J2P{>8Rpw%egHr;`*8!H3IGzFu;gL!fKfmBl$Bgd z8Bv%qc3}tJ!Ue?bbSj%0o}&Wv?L64W@AeT|aPRx+vnbUO_R_Dhg}(B~7)Hdn0u6oW z!YZ6$6ho(-PB5+gOlpwC!OVCl6AU2oWOQS=}GUT zx-=ZVZ*107\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Matrices do not have the same dimensions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma_1\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3,5) (5,2,3) " + ] + } + ], + "source": [ + "# Matrices do not have the same dimensions\n", + "c = a_1 + b" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 7.- Transpose b so that it has the same structure of a (i.e. become a 2x3x5 array). Assign the transposed array to varialbe \"c\"." + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1. 1. 1.]\n", + " [1. 1. 1.]]]\n", + "(1, 2, 3)\n", + "[[[1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]]]\n", + "(2, 1, 3)\n" + ] + } + ], + "source": [ + "x = np.ones((1, 2, 3))\n", + "print(x)\n", + "print(x.shape)\n", + "\n", + "y = np.transpose(x, (1, 0, 2))\n", + "print(y)\n", + "print(y.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "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": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c = np.transpose(b, (1, 2, 0))\n", + "c" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 8.- Try to add a and c. Now it should work. Assign the sum to varialbe \"d\". But why does it work now?" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1.12050588 1.40776605 1.12249744 1.86140904 1.57384674]\n", + " [1.45247417 1.59465225 1.7351169 1.69663346 1.36805872]\n", + " [1.03574943 1.22959237 1.18871731 1.51949819 1.02614254]]\n", + "\n", + " [[1.24330015 1.83578299 1.37107843 1.24608776 1.12703523]\n", + " [1.27614923 1.05536305 1.64462192 1.67409299 1.00965216]\n", + " [1.34555729 1.46962599 1.10100447 1.86209479 1.78358437]]]\n" + ] + } + ], + "source": [ + "d = a_1 + c\n", + "print(d)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 9.- Print a and d. Notice the difference and relation of the two array in terms of the values? Explain." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "c was transposed into a configuration that made possible the addition of a and itself. Thus, the relation between d and a is c, is it is a \"1-only\" matrix, so the only difference is the ones that were added." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 10.- Multiply a and c. Assign the result to e." + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.12050588 0.40776605 0.12249744 0.86140904 0.57384674]\n", + " [0.45247417 0.59465225 0.7351169 0.69663346 0.36805872]\n", + " [0.03574943 0.22959237 0.18871731 0.51949819 0.02614254]]\n", + "\n", + " [[0.24330015 0.83578299 0.37107843 0.24608776 0.12703523]\n", + " [0.27614923 0.05536305 0.64462192 0.67409299 0.00965216]\n", + " [0.34555729 0.46962599 0.10100447 0.86209479 0.78358437]]]\n" + ] + } + ], + "source": [ + "e = a_1*c\n", + "print(e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 11.- Does e equal to a? Why or why not?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Of course no. Something times one equals the number itself, which is totally different to adding 1 to a number which increases the value of that number by 1." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 12.- Identify the max, min, and mean values in d. Assign those values to variables \"d_max\", \"d_min\", and \"d_mean\"" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [], + "source": [ + "d_max = np.max(d)\n", + "d_min = np.min(d)\n", + "d_mean = np.mean(d)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 13.-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`." + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.12050588 0.40776605 0.12249744 0.86140904 0.57384674]\n", + " [0.45247417 0.59465225 0.7351169 0.69663346 0.36805872]\n", + " [0.03574943 0.22959237 0.18871731 0.51949819 0.02614254]]\n", + "\n", + " [[0.24330015 0.83578299 0.37107843 0.24608776 0.12703523]\n", + " [0.27614923 0.05536305 0.64462192 0.67409299 0.00965216]\n", + " [0.34555729 0.46962599 0.10100447 0.86209479 0.78358437]]]\n" + ] + } + ], + "source": [ + "f = np.empty([2, 3, 5])\n", + "print(f)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 14. 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.If a value in d is larger than d_mean but smaller than d_max, assign 75 to the corresponding value in f. If a value equals to d_mean, assign 50 to the corresponding value in f. Assign 0 to the corresponding value(s) in f for d_min in d. Assign 100 to the corresponding value(s) in f for d_max in d. In the end, f should have only the following values: 0, 25, 50, 75, and 100. Note: you don't have to use Numpy in this question." + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [], + "source": [ + "for matrix in range(d.shape[0]):\n", + " for row in range(d.shape[1]):\n", + " for num in range(d.shape[2]):\n", + " x = d[matrix][row][num]\n", + " if x > d_min and x < d_mean:\n", + " f[matrix, row, num] = 25\n", + " elif x > d_mean and x < d_max:\n", + " f[matrix, row, num] = 75\n", + " elif x == d_mean:\n", + " f[matrix, row, num] = 50\n", + " elif x == d_min:\n", + " f[matrix, row, num] = 0\n", + " elif x == d_max:\n", + " f[matrix, row, num] = 100" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[ 25., 75., 25., 75., 75.],\n", + " [ 75., 75., 75., 75., 25.],\n", + " [ 25., 25., 25., 75., 25.]],\n", + "\n", + " [[ 25., 75., 25., 25., 25.],\n", + " [ 25., 25., 75., 75., 0.],\n", + " [ 25., 75., 25., 100., 75.]]])" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 15.- 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", + " [[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", + " [[ 25., 25., 25., 25., 100.],
\n", + " [ 75., 75., 75., 75., 75.],
\n", + " [ 25., 75., 0., 75., 75.]]])
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 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", + " [[ 'B', 'B', 'B', 'B', 'E'],
\n", + " [ 'D', 'D', 'D', 'D', 'D'],
\n", + " [ 'B', 'D', 'A', 'D', 'D']]])
\n", + "\n", + "Again, you don't need Numpy in this question.
" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [], + "source": [ + "f = np.empty((2, 3, 5)).tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [], + "source": [ + "for matrix in range(d.shape[0]):\n", + " for row in range(d.shape[1]):\n", + " for num in range(d.shape[2]):\n", + " x = d[matrix][row][num]\n", + " if x > d_min and x < d_mean:\n", + " f[matrix][row][num] = 'B'\n", + " elif x > d_mean and x < d_max:\n", + " f[matrix][row][num] = 'D'\n", + " elif x == d_mean:\n", + " f[matrix][row][num] = 'C'\n", + " elif x == d_min:\n", + " f[matrix][row][num] = 'A'\n", + " elif x == d_max:\n", + " f[matrix][row][num] = 'E'" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[['B', 'D', 'B', 'D', 'D'],\n", + " ['D', 'D', 'D', 'D', 'B'],\n", + " ['B', 'B', 'B', 'D', 'B']],\n", + " [['B', 'D', 'B', 'B', 'B'],\n", + " ['B', 'B', 'D', 'D', 'A'],\n", + " ['B', 'D', 'B', 'E', 'D']]]" + ] + }, + "execution_count": 109, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/main.ipynb b/your-code/main.ipynb new file mode 100644 index 0000000..36365af --- /dev/null +++ b/your-code/main.ipynb @@ -0,0 +1,590 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 1.- Import the NUMPY package under the name np." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 2.- Print the NUMPY version and the configuration." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.21.0\n" + ] + } + ], + "source": [ + "print(np.version.version)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 3.- Generate a 2x3x5 3-dimensional array with random values. Assign the array to variable \"a\". Challenge: there are at least three easy ways that use numpy to generate random arrays. How many ways can you find. Print a" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[0.12050588, 0.40776605, 0.12249744, 0.86140904, 0.57384674],\n", + " [0.45247417, 0.59465225, 0.7351169 , 0.69663346, 0.36805872],\n", + " [0.03574943, 0.22959237, 0.18871731, 0.51949819, 0.02614254]],\n", + "\n", + " [[0.24330015, 0.83578299, 0.37107843, 0.24608776, 0.12703523],\n", + " [0.27614923, 0.05536305, 0.64462192, 0.67409299, 0.00965216],\n", + " [0.34555729, 0.46962599, 0.10100447, 0.86209479, 0.78358437]]])" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 1.-\n", + "a_1 = np.random.random((2, 3, 5))\n", + "a_1" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[0.26802817, 0.53359042, 0.26397401, 0.86041552, 0.79785231],\n", + " [0.43958104, 0.9858923 , 0.40378786, 0.3929786 , 0.42465148],\n", + " [0.75199062, 0.87563648, 0.62304009, 0.88144283, 0.7624334 ]],\n", + "\n", + " [[0.5159259 , 0.99523376, 0.54558014, 0.45800733, 0.88922872],\n", + " [0.20846266, 0.64729239, 0.3212027 , 0.13642272, 0.59748819],\n", + " [0.18911519, 0.13085156, 0.25729076, 0.09902737, 0.29642137]]])" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 3.- \n", + "a_2 = np.random.random(30).reshape(2, 3, 5)\n", + "a_2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 4.- Create a 5x2x3 3-dimensional array with all values equaling 1. Assign the array to variable \"b\". Print b." + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[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]]])" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b = np.full((5, 2, 3), 1, dtype = int)\n", + "b" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 5.- Do a and b have the same size? How do you prove that in Python code?" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "a and b DO NOT have the same size\n", + "Dimensions of a are: (2, 3, 5)\n", + "Dimensions of b are: (5, 2, 3)\n" + ] + } + ], + "source": [ + "if a_1.shape == b.shape:\n", + " print(True)\n", + " print('a and b have the same size')\n", + "else:\n", + " print(False)\n", + " print('a and b DO NOT have the same size')\n", + " print(f'Dimensions of a are: {a_1.shape}')\n", + " print(f'Dimensions of b are: {b.shape}')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 6.- Are you able to add a and b? Why or why not?" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "operands could not be broadcast together with shapes (2,3,5) (5,2,3) ", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Matrices do not have the same dimensions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma_1\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3,5) (5,2,3) " + ] + } + ], + "source": [ + "# Matrices do not have the same dimensions\n", + "c = a_1 + b" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 7.- Transpose b so that it has the same structure of a (i.e. become a 2x3x5 array). Assign the transposed array to varialbe \"c\"." + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1. 1. 1.]\n", + " [1. 1. 1.]]]\n", + "(1, 2, 3)\n", + "[[[1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]]]\n", + "(2, 1, 3)\n" + ] + } + ], + "source": [ + "x = np.ones((1, 2, 3))\n", + "print(x)\n", + "print(x.shape)\n", + "\n", + "y = np.transpose(x, (1, 0, 2))\n", + "print(y)\n", + "print(y.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "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": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c = np.transpose(b, (1, 2, 0))\n", + "c" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 8.- Try to add a and c. Now it should work. Assign the sum to varialbe \"d\". But why does it work now?" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1.12050588 1.40776605 1.12249744 1.86140904 1.57384674]\n", + " [1.45247417 1.59465225 1.7351169 1.69663346 1.36805872]\n", + " [1.03574943 1.22959237 1.18871731 1.51949819 1.02614254]]\n", + "\n", + " [[1.24330015 1.83578299 1.37107843 1.24608776 1.12703523]\n", + " [1.27614923 1.05536305 1.64462192 1.67409299 1.00965216]\n", + " [1.34555729 1.46962599 1.10100447 1.86209479 1.78358437]]]\n" + ] + } + ], + "source": [ + "d = a_1 + c\n", + "print(d)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 9.- Print a and d. Notice the difference and relation of the two array in terms of the values? Explain." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "c was transposed into a configuration that made possible the addition of a and itself. Thus, the relation between d and a is c, is it is a \"1-only\" matrix, so the only difference is the ones that were added." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 10.- Multiply a and c. Assign the result to e." + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.12050588 0.40776605 0.12249744 0.86140904 0.57384674]\n", + " [0.45247417 0.59465225 0.7351169 0.69663346 0.36805872]\n", + " [0.03574943 0.22959237 0.18871731 0.51949819 0.02614254]]\n", + "\n", + " [[0.24330015 0.83578299 0.37107843 0.24608776 0.12703523]\n", + " [0.27614923 0.05536305 0.64462192 0.67409299 0.00965216]\n", + " [0.34555729 0.46962599 0.10100447 0.86209479 0.78358437]]]\n" + ] + } + ], + "source": [ + "e = a_1*c\n", + "print(e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 11.- Does e equal to a? Why or why not?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Of course no. Something times one equals the number itself, which is totally different to adding 1 to a number which increases the value of that number by 1." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 12.- Identify the max, min, and mean values in d. Assign those values to variables \"d_max\", \"d_min\", and \"d_mean\"" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [], + "source": [ + "d_max = np.max(d)\n", + "d_min = np.min(d)\n", + "d_mean = np.mean(d)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 13.-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`." + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.12050588 0.40776605 0.12249744 0.86140904 0.57384674]\n", + " [0.45247417 0.59465225 0.7351169 0.69663346 0.36805872]\n", + " [0.03574943 0.22959237 0.18871731 0.51949819 0.02614254]]\n", + "\n", + " [[0.24330015 0.83578299 0.37107843 0.24608776 0.12703523]\n", + " [0.27614923 0.05536305 0.64462192 0.67409299 0.00965216]\n", + " [0.34555729 0.46962599 0.10100447 0.86209479 0.78358437]]]\n" + ] + } + ], + "source": [ + "f = np.empty([2, 3, 5])\n", + "print(f)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 14. 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.If a value in d is larger than d_mean but smaller than d_max, assign 75 to the corresponding value in f. If a value equals to d_mean, assign 50 to the corresponding value in f. Assign 0 to the corresponding value(s) in f for d_min in d. Assign 100 to the corresponding value(s) in f for d_max in d. In the end, f should have only the following values: 0, 25, 50, 75, and 100. Note: you don't have to use Numpy in this question." + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [], + "source": [ + "for matrix in range(d.shape[0]):\n", + " for row in range(d.shape[1]):\n", + " for num in range(d.shape[2]):\n", + " x = d[matrix][row][num]\n", + " if x > d_min and x < d_mean:\n", + " f[matrix, row, num] = 25\n", + " elif x > d_mean and x < d_max:\n", + " f[matrix, row, num] = 75\n", + " elif x == d_mean:\n", + " f[matrix, row, num] = 50\n", + " elif x == d_min:\n", + " f[matrix, row, num] = 0\n", + " elif x == d_max:\n", + " f[matrix, row, num] = 100" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[[ 25., 75., 25., 75., 75.],\n", + " [ 75., 75., 75., 75., 25.],\n", + " [ 25., 25., 25., 75., 25.]],\n", + "\n", + " [[ 25., 75., 25., 25., 25.],\n", + " [ 25., 25., 75., 75., 0.],\n", + " [ 25., 75., 25., 100., 75.]]])" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 15.- 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", + " [[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", + " [[ 25., 25., 25., 25., 100.],
\n", + " [ 75., 75., 75., 75., 75.],
\n", + " [ 25., 75., 0., 75., 75.]]])
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 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", + " [[ 'B', 'B', 'B', 'B', 'E'],
\n", + " [ 'D', 'D', 'D', 'D', 'D'],
\n", + " [ 'B', 'D', 'A', 'D', 'D']]])
\n", + "\n", + "Again, you don't need Numpy in this question.
" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [], + "source": [ + "f = np.empty((2, 3, 5)).tolist()" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [], + "source": [ + "for matrix in range(d.shape[0]):\n", + " for row in range(d.shape[1]):\n", + " for num in range(d.shape[2]):\n", + " x = d[matrix][row][num]\n", + " if x > d_min and x < d_mean:\n", + " f[matrix][row][num] = 'B'\n", + " elif x > d_mean and x < d_max:\n", + " f[matrix][row][num] = 'D'\n", + " elif x == d_mean:\n", + " f[matrix][row][num] = 'C'\n", + " elif x == d_min:\n", + " f[matrix][row][num] = 'A'\n", + " elif x == d_max:\n", + " f[matrix][row][num] = 'E'" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[['B', 'D', 'B', 'D', 'D'],\n", + " ['D', 'D', 'D', 'D', 'B'],\n", + " ['B', 'B', 'B', 'D', 'B']],\n", + " [['B', 'D', 'B', 'B', 'B'],\n", + " ['B', 'B', 'D', 'D', 'A'],\n", + " ['B', 'D', 'B', 'E', 'D']]]" + ] + }, + "execution_count": 109, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/main.py b/your-code/main.py index 78c792b..fe31d97 100644 --- a/your-code/main.py +++ b/your-code/main.py @@ -1,7 +1,6 @@ #1. Import the NUMPY package under the name np. - #2. Print the NUMPY version and the configuration. From 0d68721afc525313ac9be5c3a420df306753a5ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20P=C3=A9rez=20Ortega?= Date: Thu, 22 Jul 2021 17:12:17 -0500 Subject: [PATCH 2/2] Lab terminado --- .../.ipynb_checkpoints/main-checkpoint.ipynb | 139 +++++++++--------- your-code/main.ipynb | 139 +++++++++--------- 2 files changed, 132 insertions(+), 146 deletions(-) diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb index 36365af..fc859a6 100644 --- a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -49,22 +49,22 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[[0.12050588, 0.40776605, 0.12249744, 0.86140904, 0.57384674],\n", - " [0.45247417, 0.59465225, 0.7351169 , 0.69663346, 0.36805872],\n", - " [0.03574943, 0.22959237, 0.18871731, 0.51949819, 0.02614254]],\n", + "array([[[0.17587677, 0.3813641 , 0.6251925 , 0.71451247, 0.71466546],\n", + " [0.397129 , 0.41592668, 0.14682988, 0.56041101, 0.21933926],\n", + " [0.59025395, 0.79489513, 0.35198264, 0.22058347, 0.03169599]],\n", "\n", - " [[0.24330015, 0.83578299, 0.37107843, 0.24608776, 0.12703523],\n", - " [0.27614923, 0.05536305, 0.64462192, 0.67409299, 0.00965216],\n", - " [0.34555729, 0.46962599, 0.10100447, 0.86209479, 0.78358437]]])" + " [[0.33371759, 0.04717761, 0.79779299, 0.3259222 , 0.99089213],\n", + " [0.49865696, 0.23321342, 0.70795892, 0.67157786, 0.47678929],\n", + " [0.97061393, 0.59173887, 0.20081984, 0.74445459, 0.33515286]]])" ] }, - "execution_count": 33, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -77,22 +77,22 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[[0.26802817, 0.53359042, 0.26397401, 0.86041552, 0.79785231],\n", - " [0.43958104, 0.9858923 , 0.40378786, 0.3929786 , 0.42465148],\n", - " [0.75199062, 0.87563648, 0.62304009, 0.88144283, 0.7624334 ]],\n", + "array([[[0.12253001, 0.23204466, 0.05318327, 0.75305589, 0.38695835],\n", + " [0.06507331, 0.53373402, 0.56534184, 0.96607451, 0.90444341],\n", + " [0.08427719, 0.06198972, 0.71258041, 0.69541678, 0.09113022]],\n", "\n", - " [[0.5159259 , 0.99523376, 0.54558014, 0.45800733, 0.88922872],\n", - " [0.20846266, 0.64729239, 0.3212027 , 0.13642272, 0.59748819],\n", - " [0.18911519, 0.13085156, 0.25729076, 0.09902737, 0.29642137]]])" + " [[0.49985424, 0.72953171, 0.82568618, 0.28445211, 0.09408022],\n", + " [0.55287048, 0.16976278, 0.46469315, 0.94171563, 0.02922495],\n", + " [0.14662571, 0.38956247, 0.02650157, 0.14960273, 0.63225123]]])" ] }, - "execution_count": 34, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -112,7 +112,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -134,7 +134,7 @@ " [1, 1, 1]]])" ] }, - "execution_count": 35, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -153,7 +153,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -187,7 +187,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -197,7 +197,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Matrices do not have the same dimensions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma_1\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Matrices do not have the same dimensions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma_1\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3,5) (5,2,3) " ] } @@ -216,7 +216,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -245,7 +245,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -260,7 +260,7 @@ " [1, 1, 1, 1, 1]]])" ] }, - "execution_count": 56, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -279,20 +279,20 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[[1.12050588 1.40776605 1.12249744 1.86140904 1.57384674]\n", - " [1.45247417 1.59465225 1.7351169 1.69663346 1.36805872]\n", - " [1.03574943 1.22959237 1.18871731 1.51949819 1.02614254]]\n", + "[[[1.17587677 1.3813641 1.6251925 1.71451247 1.71466546]\n", + " [1.397129 1.41592668 1.14682988 1.56041101 1.21933926]\n", + " [1.59025395 1.79489513 1.35198264 1.22058347 1.03169599]]\n", "\n", - " [[1.24330015 1.83578299 1.37107843 1.24608776 1.12703523]\n", - " [1.27614923 1.05536305 1.64462192 1.67409299 1.00965216]\n", - " [1.34555729 1.46962599 1.10100447 1.86209479 1.78358437]]]\n" + " [[1.33371759 1.04717761 1.79779299 1.3259222 1.99089213]\n", + " [1.49865696 1.23321342 1.70795892 1.67157786 1.47678929]\n", + " [1.97061393 1.59173887 1.20081984 1.74445459 1.33515286]]]\n" ] } ], @@ -324,20 +324,20 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[[0.12050588 0.40776605 0.12249744 0.86140904 0.57384674]\n", - " [0.45247417 0.59465225 0.7351169 0.69663346 0.36805872]\n", - " [0.03574943 0.22959237 0.18871731 0.51949819 0.02614254]]\n", + "[[[0.17587677 0.3813641 0.6251925 0.71451247 0.71466546]\n", + " [0.397129 0.41592668 0.14682988 0.56041101 0.21933926]\n", + " [0.59025395 0.79489513 0.35198264 0.22058347 0.03169599]]\n", "\n", - " [[0.24330015 0.83578299 0.37107843 0.24608776 0.12703523]\n", - " [0.27614923 0.05536305 0.64462192 0.67409299 0.00965216]\n", - " [0.34555729 0.46962599 0.10100447 0.86209479 0.78358437]]]\n" + " [[0.33371759 0.04717761 0.79779299 0.3259222 0.99089213]\n", + " [0.49865696 0.23321342 0.70795892 0.67157786 0.47678929]\n", + " [0.97061393 0.59173887 0.20081984 0.74445459 0.33515286]]]\n" ] } ], @@ -369,7 +369,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -387,20 +387,20 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[[0.12050588 0.40776605 0.12249744 0.86140904 0.57384674]\n", - " [0.45247417 0.59465225 0.7351169 0.69663346 0.36805872]\n", - " [0.03574943 0.22959237 0.18871731 0.51949819 0.02614254]]\n", + "[[[0.17587677 0.3813641 0.6251925 0.71451247 0.71466546]\n", + " [0.397129 0.41592668 0.14682988 0.56041101 0.21933926]\n", + " [0.59025395 0.79489513 0.35198264 0.22058347 0.03169599]]\n", "\n", - " [[0.24330015 0.83578299 0.37107843 0.24608776 0.12703523]\n", - " [0.27614923 0.05536305 0.64462192 0.67409299 0.00965216]\n", - " [0.34555729 0.46962599 0.10100447 0.86209479 0.78358437]]]\n" + " [[0.33371759 0.04717761 0.79779299 0.3259222 0.99089213]\n", + " [0.49865696 0.23321342 0.70795892 0.67157786 0.47678929]\n", + " [0.97061393 0.59173887 0.20081984 0.74445459 0.33515286]]]\n" ] } ], @@ -418,7 +418,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -440,22 +440,22 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[[ 25., 75., 25., 75., 75.],\n", - " [ 75., 75., 75., 75., 25.],\n", - " [ 25., 25., 25., 75., 25.]],\n", + "array([[[ 25., 25., 75., 75., 75.],\n", + " [ 25., 25., 25., 75., 25.],\n", + " [ 75., 75., 25., 25., 0.]],\n", "\n", - " [[ 25., 75., 25., 25., 25.],\n", - " [ 25., 25., 75., 75., 0.],\n", - " [ 25., 75., 25., 100., 75.]]])" + " [[ 25., 25., 75., 25., 100.],\n", + " [ 75., 25., 75., 75., 75.],\n", + " [ 75., 75., 25., 75., 25.]]])" ] }, - "execution_count": 95, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -504,7 +504,7 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -513,7 +513,7 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -535,21 +535,21 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[[['B', 'D', 'B', 'D', 'D'],\n", - " ['D', 'D', 'D', 'D', 'B'],\n", - " ['B', 'B', 'B', 'D', 'B']],\n", - " [['B', 'D', 'B', 'B', 'B'],\n", - " ['B', 'B', 'D', 'D', 'A'],\n", - " ['B', 'D', 'B', 'E', 'D']]]" + "[[['B', 'B', 'D', 'D', 'D'],\n", + " ['B', 'B', 'B', 'D', 'B'],\n", + " ['D', 'D', 'B', 'B', 'A']],\n", + " [['B', 'B', 'D', 'B', 'E'],\n", + " ['D', 'B', 'D', 'D', 'D'],\n", + " ['D', 'D', 'B', 'D', 'B']]]" ] }, - "execution_count": 109, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -557,13 +557,6 @@ "source": [ "f" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 36365af..fc859a6 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -49,22 +49,22 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[[0.12050588, 0.40776605, 0.12249744, 0.86140904, 0.57384674],\n", - " [0.45247417, 0.59465225, 0.7351169 , 0.69663346, 0.36805872],\n", - " [0.03574943, 0.22959237, 0.18871731, 0.51949819, 0.02614254]],\n", + "array([[[0.17587677, 0.3813641 , 0.6251925 , 0.71451247, 0.71466546],\n", + " [0.397129 , 0.41592668, 0.14682988, 0.56041101, 0.21933926],\n", + " [0.59025395, 0.79489513, 0.35198264, 0.22058347, 0.03169599]],\n", "\n", - " [[0.24330015, 0.83578299, 0.37107843, 0.24608776, 0.12703523],\n", - " [0.27614923, 0.05536305, 0.64462192, 0.67409299, 0.00965216],\n", - " [0.34555729, 0.46962599, 0.10100447, 0.86209479, 0.78358437]]])" + " [[0.33371759, 0.04717761, 0.79779299, 0.3259222 , 0.99089213],\n", + " [0.49865696, 0.23321342, 0.70795892, 0.67157786, 0.47678929],\n", + " [0.97061393, 0.59173887, 0.20081984, 0.74445459, 0.33515286]]])" ] }, - "execution_count": 33, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -77,22 +77,22 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[[0.26802817, 0.53359042, 0.26397401, 0.86041552, 0.79785231],\n", - " [0.43958104, 0.9858923 , 0.40378786, 0.3929786 , 0.42465148],\n", - " [0.75199062, 0.87563648, 0.62304009, 0.88144283, 0.7624334 ]],\n", + "array([[[0.12253001, 0.23204466, 0.05318327, 0.75305589, 0.38695835],\n", + " [0.06507331, 0.53373402, 0.56534184, 0.96607451, 0.90444341],\n", + " [0.08427719, 0.06198972, 0.71258041, 0.69541678, 0.09113022]],\n", "\n", - " [[0.5159259 , 0.99523376, 0.54558014, 0.45800733, 0.88922872],\n", - " [0.20846266, 0.64729239, 0.3212027 , 0.13642272, 0.59748819],\n", - " [0.18911519, 0.13085156, 0.25729076, 0.09902737, 0.29642137]]])" + " [[0.49985424, 0.72953171, 0.82568618, 0.28445211, 0.09408022],\n", + " [0.55287048, 0.16976278, 0.46469315, 0.94171563, 0.02922495],\n", + " [0.14662571, 0.38956247, 0.02650157, 0.14960273, 0.63225123]]])" ] }, - "execution_count": 34, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -112,7 +112,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -134,7 +134,7 @@ " [1, 1, 1]]])" ] }, - "execution_count": 35, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -153,7 +153,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -187,7 +187,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -197,7 +197,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Matrices do not have the same dimensions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma_1\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# Matrices do not have the same dimensions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma_1\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3,5) (5,2,3) " ] } @@ -216,7 +216,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -245,7 +245,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -260,7 +260,7 @@ " [1, 1, 1, 1, 1]]])" ] }, - "execution_count": 56, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -279,20 +279,20 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[[1.12050588 1.40776605 1.12249744 1.86140904 1.57384674]\n", - " [1.45247417 1.59465225 1.7351169 1.69663346 1.36805872]\n", - " [1.03574943 1.22959237 1.18871731 1.51949819 1.02614254]]\n", + "[[[1.17587677 1.3813641 1.6251925 1.71451247 1.71466546]\n", + " [1.397129 1.41592668 1.14682988 1.56041101 1.21933926]\n", + " [1.59025395 1.79489513 1.35198264 1.22058347 1.03169599]]\n", "\n", - " [[1.24330015 1.83578299 1.37107843 1.24608776 1.12703523]\n", - " [1.27614923 1.05536305 1.64462192 1.67409299 1.00965216]\n", - " [1.34555729 1.46962599 1.10100447 1.86209479 1.78358437]]]\n" + " [[1.33371759 1.04717761 1.79779299 1.3259222 1.99089213]\n", + " [1.49865696 1.23321342 1.70795892 1.67157786 1.47678929]\n", + " [1.97061393 1.59173887 1.20081984 1.74445459 1.33515286]]]\n" ] } ], @@ -324,20 +324,20 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[[0.12050588 0.40776605 0.12249744 0.86140904 0.57384674]\n", - " [0.45247417 0.59465225 0.7351169 0.69663346 0.36805872]\n", - " [0.03574943 0.22959237 0.18871731 0.51949819 0.02614254]]\n", + "[[[0.17587677 0.3813641 0.6251925 0.71451247 0.71466546]\n", + " [0.397129 0.41592668 0.14682988 0.56041101 0.21933926]\n", + " [0.59025395 0.79489513 0.35198264 0.22058347 0.03169599]]\n", "\n", - " [[0.24330015 0.83578299 0.37107843 0.24608776 0.12703523]\n", - " [0.27614923 0.05536305 0.64462192 0.67409299 0.00965216]\n", - " [0.34555729 0.46962599 0.10100447 0.86209479 0.78358437]]]\n" + " [[0.33371759 0.04717761 0.79779299 0.3259222 0.99089213]\n", + " [0.49865696 0.23321342 0.70795892 0.67157786 0.47678929]\n", + " [0.97061393 0.59173887 0.20081984 0.74445459 0.33515286]]]\n" ] } ], @@ -369,7 +369,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -387,20 +387,20 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[[0.12050588 0.40776605 0.12249744 0.86140904 0.57384674]\n", - " [0.45247417 0.59465225 0.7351169 0.69663346 0.36805872]\n", - " [0.03574943 0.22959237 0.18871731 0.51949819 0.02614254]]\n", + "[[[0.17587677 0.3813641 0.6251925 0.71451247 0.71466546]\n", + " [0.397129 0.41592668 0.14682988 0.56041101 0.21933926]\n", + " [0.59025395 0.79489513 0.35198264 0.22058347 0.03169599]]\n", "\n", - " [[0.24330015 0.83578299 0.37107843 0.24608776 0.12703523]\n", - " [0.27614923 0.05536305 0.64462192 0.67409299 0.00965216]\n", - " [0.34555729 0.46962599 0.10100447 0.86209479 0.78358437]]]\n" + " [[0.33371759 0.04717761 0.79779299 0.3259222 0.99089213]\n", + " [0.49865696 0.23321342 0.70795892 0.67157786 0.47678929]\n", + " [0.97061393 0.59173887 0.20081984 0.74445459 0.33515286]]]\n" ] } ], @@ -418,7 +418,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -440,22 +440,22 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[[ 25., 75., 25., 75., 75.],\n", - " [ 75., 75., 75., 75., 25.],\n", - " [ 25., 25., 25., 75., 25.]],\n", + "array([[[ 25., 25., 75., 75., 75.],\n", + " [ 25., 25., 25., 75., 25.],\n", + " [ 75., 75., 25., 25., 0.]],\n", "\n", - " [[ 25., 75., 25., 25., 25.],\n", - " [ 25., 25., 75., 75., 0.],\n", - " [ 25., 75., 25., 100., 75.]]])" + " [[ 25., 25., 75., 25., 100.],\n", + " [ 75., 25., 75., 75., 75.],\n", + " [ 75., 75., 25., 75., 25.]]])" ] }, - "execution_count": 95, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -504,7 +504,7 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -513,7 +513,7 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -535,21 +535,21 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[[['B', 'D', 'B', 'D', 'D'],\n", - " ['D', 'D', 'D', 'D', 'B'],\n", - " ['B', 'B', 'B', 'D', 'B']],\n", - " [['B', 'D', 'B', 'B', 'B'],\n", - " ['B', 'B', 'D', 'D', 'A'],\n", - " ['B', 'D', 'B', 'E', 'D']]]" + "[[['B', 'B', 'D', 'D', 'D'],\n", + " ['B', 'B', 'B', 'D', 'B'],\n", + " ['D', 'D', 'B', 'B', 'A']],\n", + " [['B', 'B', 'D', 'B', 'E'],\n", + " ['D', 'B', 'D', 'D', 'D'],\n", + " ['D', 'D', 'B', 'D', 'B']]]" ] }, - "execution_count": 109, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -557,13 +557,6 @@ "source": [ "f" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {