diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..3dcd909 Binary files /dev/null and b/.DS_Store differ diff --git a/your-code/.DS_Store b/your-code/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/your-code/.DS_Store differ diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb new file mode 100644 index 0000000..2fd6442 --- /dev/null +++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/main.ipynb b/your-code/main.ipynb new file mode 100644 index 0000000..e586ee0 --- /dev/null +++ b/your-code/main.ipynb @@ -0,0 +1,525 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#1. Import the NUMPY package under the name np.\n", + "\n", + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'1.16.4'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#2. Print the NUMPY version and the configuration.\n", + "\n", + "np.version.version" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.21147871 0.75804237 0.9115814 0.40667329 0.53182288]\n", + " [0.98374763 0.54271426 0.88799577 0.13082761 0.55748123]\n", + " [0.30306828 0.86861946 0.7067565 0.21372597 0.89081739]]\n", + "\n", + " [[0.8598921 0.02632583 0.90106924 0.07250084 0.03533543]\n", + " [0.48241424 0.76747678 0.5778101 0.06510067 0.91968937]\n", + " [0.63679283 0.01218623 0.79229505 0.21035119 0.66692815]]]\n", + "[[[258 535 2 264 689]\n", + " [812 825 978 573 726]\n", + " [474 378 528 917 619]]\n", + "\n", + " [[843 949 484 498 974]\n", + " [853 905 57 592 185]\n", + " [250 997 465 546 776]]]\n" + ] + } + ], + "source": [ + "#3. Generate a 2x3x5 3-dimensional array with random values. Assign the array to variable \"a\"\n", + "#4. Print a.\n", + "\n", + "a = np.random.random((2,3,5))\n", + "print(a)\n", + "\n", + "a2 = np.random.randint(low=0, high=1000, size=(2,3,5))\n", + "print(a2)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "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", + "[[[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", + "#Assign the array to variable \"b\"\n", + "#6. Print b.\n", + "\n", + "b = np.full((5,2,3),1)\n", + "print(b)\n", + "\n", + "b2 = np.ones((5,2,3))\n", + "print(b2)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "#7. Do a and b have the same size? How do you prove that in Python code?\n", + "\n", + "if a.size == b.size:\n", + " print(\"True\")\n", + "else:\n", + " print(\"False\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#8. Are you able to add a and b? Why or why not?\n", + "\n", + "Nel no son las mismas dimensiones (python no reescribre la matemática)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[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]]]\n" + ] + } + ], + "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", + "\n", + "c = np.reshape(b,(2,3,5))\n", + "print(c)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1.21147871 1.75804237 1.9115814 1.40667329 1.53182288]\n", + " [1.98374763 1.54271426 1.88799577 1.13082761 1.55748123]\n", + " [1.30306828 1.86861946 1.7067565 1.21372597 1.89081739]]\n", + "\n", + " [[1.8598921 1.02632583 1.90106924 1.07250084 1.03533543]\n", + " [1.48241424 1.76747678 1.5778101 1.06510067 1.91968937]\n", + " [1.63679283 1.01218623 1.79229505 1.21035119 1.66692815]]]\n" + ] + } + ], + "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", + "\n", + "d = a+c\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ahora si, las dimenciones son las mismas " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.21147871 0.75804237 0.9115814 0.40667329 0.53182288]\n", + " [0.98374763 0.54271426 0.88799577 0.13082761 0.55748123]\n", + " [0.30306828 0.86861946 0.7067565 0.21372597 0.89081739]]\n", + "\n", + " [[0.8598921 0.02632583 0.90106924 0.07250084 0.03533543]\n", + " [0.48241424 0.76747678 0.5778101 0.06510067 0.91968937]\n", + " [0.63679283 0.01218623 0.79229505 0.21035119 0.66692815]]]\n", + "[[[1.21147871 1.75804237 1.9115814 1.40667329 1.53182288]\n", + " [1.98374763 1.54271426 1.88799577 1.13082761 1.55748123]\n", + " [1.30306828 1.86861946 1.7067565 1.21372597 1.89081739]]\n", + "\n", + " [[1.8598921 1.02632583 1.90106924 1.07250084 1.03533543]\n", + " [1.48241424 1.76747678 1.5778101 1.06510067 1.91968937]\n", + " [1.63679283 1.01218623 1.79229505 1.21035119 1.66692815]]]\n" + ] + } + ], + "source": [ + "#11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain.\n", + "\n", + "print(a)\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "La matriz \"d\" tiene una unidad más que la \"a\" " + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.21147871 0.75804237 0.9115814 0.40667329 0.53182288]\n", + " [0.98374763 0.54271426 0.88799577 0.13082761 0.55748123]\n", + " [0.30306828 0.86861946 0.7067565 0.21372597 0.89081739]]\n", + "\n", + " [[0.8598921 0.02632583 0.90106924 0.07250084 0.03533543]\n", + " [0.48241424 0.76747678 0.5778101 0.06510067 0.91968937]\n", + " [0.63679283 0.01218623 0.79229505 0.21035119 0.66692815]]]\n" + ] + } + ], + "source": [ + "#12. Multiply a and c. Assign the result to e.\n", + "\n", + "e = a*c\n", + "print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#13. Does e equal to a? Why or why not?\n", + "\n", + "Ps si, se multiplicó por 1 no manches" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.983747626836083\n", + "1.0121862260860133\n", + "1.531050692419854\n" + ] + } + ], + "source": [ + "#14. Identify the max, min, and mean values in d. Assign those values to variables \"d_max\", \"d_min\", and \"d_mean\".\n", + "\n", + "d_max = np.amax(d)\n", + "print(d_max)\n", + "d_min = np.amin(d)\n", + "print(d_min)\n", + "d_mean = np.mean(d)\n", + "print(d_mean)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.21147871 0.75804237 0.9115814 0.40667329 0.53182288]\n", + " [0.98374763 0.54271426 0.88799577 0.13082761 0.55748123]\n", + " [0.30306828 0.86861946 0.7067565 0.21372597 0.89081739]]\n", + "\n", + " [[0.8598921 0.02632583 0.90106924 0.07250084 0.03533543]\n", + " [0.48241424 0.76747678 0.5778101 0.06510067 0.91968937]\n", + " [0.63679283 0.01218623 0.79229505 0.21035119 0.66692815]]]\n" + ] + } + ], + "source": [ + "#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", + "f = np.empty([2,3,5])\n", + "print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 1.211478712467478\n", + "1 1.7580423654782424\n", + "2 1.9115814014272692\n", + "3 1.4066732947736849\n", + "4 1.531822879894447\n", + "0 1.983747626836083\n", + "1 1.542714256073828\n", + "2 1.887995767307331\n", + "3 1.1308276055223487\n", + "4 1.557481232506913\n", + "0 1.3030682774695825\n", + "1 1.8686194614604958\n", + "2 1.7067565011962236\n", + "3 1.2137259695321427\n", + "4 1.8908173850031273\n", + "0 1.8598921042930185\n", + "1 1.0263258309293926\n", + "2 1.9010692394796234\n", + "3 1.0725008444600972\n", + "4 1.0353354251282092\n", + "0 1.4824142400485254\n", + "1 1.7674767785449834\n", + "2 1.577810097145484\n", + "3 1.0651006683450883\n", + "4 1.9196893735647433\n", + "0 1.6367928278426498\n", + "1 1.0121862260860133\n", + "2 1.7922950482196591\n", + "3 1.2103511851073276\n", + "4 1.6669281464516108\n" + ] + } + ], + "source": [ + "#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", + "for i,a in enumerate(d):\n", + " #print(i,a)\n", + " for x,b in enumerate(a):\n", + " #print(x,b)\n", + " for y,c in enumerate(b):\n", + " print(y,c)\n", + " if c > d_min and c < d_mean:\n", + " f[i][x][y] = 25\n", + " elif c > d_mean and c < d_max:\n", + " f[i][x][y] = 75\n", + " elif c == d_mean:\n", + " f[i][x][y] = 50\n", + " elif c == d_min:\n", + " f[i][x][y] = 0\n", + " elif c == d_max:\n", + " f[i][x][y] = 100" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1.21147871 1.75804237 1.9115814 1.40667329 1.53182288]\n", + " [1.98374763 1.54271426 1.88799577 1.13082761 1.55748123]\n", + " [1.30306828 1.86861946 1.7067565 1.21372597 1.89081739]]\n", + "\n", + " [[1.8598921 1.02632583 1.90106924 1.07250084 1.03533543]\n", + " [1.48241424 1.76747678 1.5778101 1.06510067 1.91968937]\n", + " [1.63679283 1.01218623 1.79229505 1.21035119 1.66692815]]]\n", + "[[[ 25. 75. 75. 25. 75.]\n", + " [100. 75. 75. 25. 75.]\n", + " [ 25. 75. 75. 25. 75.]]\n", + "\n", + " [[ 75. 25. 75. 25. 25.]\n", + " [ 25. 75. 75. 25. 75.]\n", + " [ 75. 0. 75. 25. 75.]]]\n" + ] + } + ], + "source": [ + "#17. Print d and f. Do you have your expected f?\n", + "\n", + "print(d)\n", + "print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[['B' 'D' 'D' 'B' 'D']\n", + " ['E' 'D' 'D' 'B' 'D']\n", + " ['B' 'D' 'D' 'B' 'D']]\n", + "\n", + " [['D' 'B' 'D' 'B' 'B']\n", + " ['B' 'D' 'D' 'B' 'D']\n", + " ['D' 'A' 'D' 'B' 'D']]]\n" + ] + } + ], + "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", + "\n", + "ff = np.empty([2,3,5],dtype=\"object\")\n", + "\n", + "for i,a in enumerate(d):\n", + " #print(i,a)\n", + " for x,b in enumerate(a):\n", + " #print(x,b)\n", + " for y,c in enumerate(b):\n", + " #print(y,c)\n", + " if c > d_min and c < d_mean:\n", + " ff[i][x][y] = \"B\"\n", + " elif c > d_mean and c < d_max:\n", + " ff[i][x][y] = \"D\"\n", + " elif c == d_mean:\n", + " ff[i][x][y] = \"C\"\n", + " elif c == d_min:\n", + " ff[i][x][y] = \"A\"\n", + " elif c == d_max:\n", + " ff[i][x][y] = \"E\"\n", + "print(ff)" + ] + }, + { + "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.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}