From d7e334220a9f9c46dd99f2868054e8c9b8df97e0 Mon Sep 17 00:00:00 2001 From: KarenLizzette Date: Sat, 12 Oct 2019 16:30:23 -0500 Subject: [PATCH 1/2] Finished. --- .../main_code-checkpoint.ipynb | 443 ++++++++++++++++++ your-code/main_code.ipynb | 443 ++++++++++++++++++ 2 files changed, 886 insertions(+) create mode 100644 your-code/.ipynb_checkpoints/main_code-checkpoint.ipynb create mode 100644 your-code/main_code.ipynb diff --git a/your-code/.ipynb_checkpoints/main_code-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main_code-checkpoint.ipynb new file mode 100644 index 0000000..57dc94c --- /dev/null +++ b/your-code/.ipynb_checkpoints/main_code-checkpoint.ipynb @@ -0,0 +1,443 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as numpy" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'1.16.5'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "numpy.version.version" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.04481475 0.38985341 0.49217271 0.49457721 0.21676157]\n", + " [0.5156023 0.96249459 0.75039841 0.56715178 0.56133307]\n", + " [0.79692126 0.19150764 0.16139519 0.66684117 0.48317794]]\n", + "\n", + " [[0.98375052 0.96953102 0.67860822 0.08797875 0.75146028]\n", + " [0.24008013 0.54515745 0.89102682 0.94231445 0.67131314]\n", + " [0.78124593 0.77789658 0.76329299 0.67676109 0.84266097]]]\n", + "[[[ 86 806 524 272 669]\n", + " [227 394 892 153 181]\n", + " [279 858 883 19 438]]\n", + "\n", + " [[852 581 802 387 325]\n", + " [188 38 664 915 516]\n", + " [438 602 401 910 106]]]\n" + ] + } + ], + "source": [ + "a = numpy.random.random((2,3,5))\n", + "print(a)\n", + "\n", + "a2 = numpy.random.randint(low=0, high=1000, size=(2,3,5))\n", + "print(a2)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "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": [ + "b = numpy.full((5,2,3),1)\n", + "print(b)\n", + "\n", + "b2 = numpy.ones((5,2,3))\n", + "print(b2)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "if a.size == b.size:\n", + " print(\"True\")\n", + "else:\n", + " print(\"False\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "It does not work because the dimensions are different." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "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": [ + "c = numpy.reshape(b,(2,3,5))\n", + "print(c)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1.04481475 1.38985341 1.49217271 1.49457721 1.21676157]\n", + " [1.5156023 1.96249459 1.75039841 1.56715178 1.56133307]\n", + " [1.79692126 1.19150764 1.16139519 1.66684117 1.48317794]]\n", + "\n", + " [[1.98375052 1.96953102 1.67860822 1.08797875 1.75146028]\n", + " [1.24008013 1.54515745 1.89102682 1.94231445 1.67131314]\n", + " [1.78124593 1.77789658 1.76329299 1.67676109 1.84266097]]]\n" + ] + } + ], + "source": [ + "d = a+c\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "It works because the shape of the matrix is the same." + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.04481475 0.38985341 0.49217271 0.49457721 0.21676157]\n", + " [0.5156023 0.96249459 0.75039841 0.56715178 0.56133307]\n", + " [0.79692126 0.19150764 0.16139519 0.66684117 0.48317794]]\n", + "\n", + " [[0.98375052 0.96953102 0.67860822 0.08797875 0.75146028]\n", + " [0.24008013 0.54515745 0.89102682 0.94231445 0.67131314]\n", + " [0.78124593 0.77789658 0.76329299 0.67676109 0.84266097]]]\n", + "[[[1.04481475 1.38985341 1.49217271 1.49457721 1.21676157]\n", + " [1.5156023 1.96249459 1.75039841 1.56715178 1.56133307]\n", + " [1.79692126 1.19150764 1.16139519 1.66684117 1.48317794]]\n", + "\n", + " [[1.98375052 1.96953102 1.67860822 1.08797875 1.75146028]\n", + " [1.24008013 1.54515745 1.89102682 1.94231445 1.67131314]\n", + " [1.78124593 1.77789658 1.76329299 1.67676109 1.84266097]]]\n" + ] + } + ], + "source": [ + "print(a)\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "The items of the matrix \"d\" is one unit more." + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.04481475 0.38985341 0.49217271 0.49457721 0.21676157]\n", + " [0.5156023 0.96249459 0.75039841 0.56715178 0.56133307]\n", + " [0.79692126 0.19150764 0.16139519 0.66684117 0.48317794]]\n", + "\n", + " [[0.98375052 0.96953102 0.67860822 0.08797875 0.75146028]\n", + " [0.24008013 0.54515745 0.89102682 0.94231445 0.67131314]\n", + " [0.78124593 0.77789658 0.76329299 0.67676109 0.84266097]]]\n" + ] + } + ], + "source": [ + "e = a*c\n", + "print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Yes, it is equal because it is multiplied by 1." + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.983750518868177\n", + "1.0448147498937645\n", + "1.5966027113157943\n" + ] + } + ], + "source": [ + "d_max = numpy.amax(d)\n", + "print(d_max)\n", + "d_min = numpy.amin(d)\n", + "print(d_min)\n", + "d_mean = numpy.mean(d)\n", + "print(d_mean)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.04481475 0.38985341 0.49217271 0.49457721 0.21676157]\n", + " [0.5156023 0.96249459 0.75039841 0.56715178 0.56133307]\n", + " [0.79692126 0.19150764 0.16139519 0.66684117 0.48317794]]\n", + "\n", + " [[0.98375052 0.96953102 0.67860822 0.08797875 0.75146028]\n", + " [0.24008013 0.54515745 0.89102682 0.94231445 0.67131314]\n", + " [0.78124593 0.77789658 0.76329299 0.67676109 0.84266097]]]\n" + ] + } + ], + "source": [ + "f = numpy.empty([2,3,5])\n", + "print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 1.0448147498937645\n", + "1 1.3898534080526732\n", + "2 1.4921727080306226\n", + "3 1.4945772130914365\n", + "4 1.216761565944525\n", + "0 1.5156022998290024\n", + "1 1.9624945916975631\n", + "2 1.7503984126265975\n", + "3 1.5671517849784076\n", + "4 1.561333071601572\n", + "0 1.7969212602531952\n", + "1 1.1915076350063947\n", + "2 1.1613951923916253\n", + "3 1.6668411668239447\n", + "4 1.4831779416810331\n", + "0 1.983750518868177\n", + "1 1.969531018494684\n", + "2 1.6786082228834156\n", + "3 1.0879787464833446\n", + "4 1.7514602802143064\n", + "0 1.24008012685348\n", + "1 1.5451574469927516\n", + "2 1.8910268235125298\n", + "3 1.9423144465656903\n", + "4 1.6713131423002823\n", + "0 1.7812459253699091\n", + "1 1.7778965828219429\n", + "2 1.7632929912364417\n", + "3 1.676761090020392\n", + "4 1.8426609749541183\n" + ] + } + ], + "source": [ + "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\n", + "#print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1.04481475 1.38985341 1.49217271 1.49457721 1.21676157]\n", + " [1.5156023 1.96249459 1.75039841 1.56715178 1.56133307]\n", + " [1.79692126 1.19150764 1.16139519 1.66684117 1.48317794]]\n", + "\n", + " [[1.98375052 1.96953102 1.67860822 1.08797875 1.75146028]\n", + " [1.24008013 1.54515745 1.89102682 1.94231445 1.67131314]\n", + " [1.78124593 1.77789658 1.76329299 1.67676109 1.84266097]]]\n", + "[[[ 0. 25. 25. 25. 25.]\n", + " [ 25. 75. 75. 25. 25.]\n", + " [ 75. 25. 25. 75. 25.]]\n", + "\n", + " [[100. 75. 75. 25. 75.]\n", + " [ 25. 25. 75. 75. 75.]\n", + " [ 75. 75. 75. 75. 75.]]]\n" + ] + } + ], + "source": [ + "print(d)\n", + "print(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.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/your-code/main_code.ipynb b/your-code/main_code.ipynb new file mode 100644 index 0000000..57dc94c --- /dev/null +++ b/your-code/main_code.ipynb @@ -0,0 +1,443 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as numpy" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'1.16.5'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "numpy.version.version" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.04481475 0.38985341 0.49217271 0.49457721 0.21676157]\n", + " [0.5156023 0.96249459 0.75039841 0.56715178 0.56133307]\n", + " [0.79692126 0.19150764 0.16139519 0.66684117 0.48317794]]\n", + "\n", + " [[0.98375052 0.96953102 0.67860822 0.08797875 0.75146028]\n", + " [0.24008013 0.54515745 0.89102682 0.94231445 0.67131314]\n", + " [0.78124593 0.77789658 0.76329299 0.67676109 0.84266097]]]\n", + "[[[ 86 806 524 272 669]\n", + " [227 394 892 153 181]\n", + " [279 858 883 19 438]]\n", + "\n", + " [[852 581 802 387 325]\n", + " [188 38 664 915 516]\n", + " [438 602 401 910 106]]]\n" + ] + } + ], + "source": [ + "a = numpy.random.random((2,3,5))\n", + "print(a)\n", + "\n", + "a2 = numpy.random.randint(low=0, high=1000, size=(2,3,5))\n", + "print(a2)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "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": [ + "b = numpy.full((5,2,3),1)\n", + "print(b)\n", + "\n", + "b2 = numpy.ones((5,2,3))\n", + "print(b2)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "if a.size == b.size:\n", + " print(\"True\")\n", + "else:\n", + " print(\"False\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "It does not work because the dimensions are different." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "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": [ + "c = numpy.reshape(b,(2,3,5))\n", + "print(c)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1.04481475 1.38985341 1.49217271 1.49457721 1.21676157]\n", + " [1.5156023 1.96249459 1.75039841 1.56715178 1.56133307]\n", + " [1.79692126 1.19150764 1.16139519 1.66684117 1.48317794]]\n", + "\n", + " [[1.98375052 1.96953102 1.67860822 1.08797875 1.75146028]\n", + " [1.24008013 1.54515745 1.89102682 1.94231445 1.67131314]\n", + " [1.78124593 1.77789658 1.76329299 1.67676109 1.84266097]]]\n" + ] + } + ], + "source": [ + "d = a+c\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "It works because the shape of the matrix is the same." + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.04481475 0.38985341 0.49217271 0.49457721 0.21676157]\n", + " [0.5156023 0.96249459 0.75039841 0.56715178 0.56133307]\n", + " [0.79692126 0.19150764 0.16139519 0.66684117 0.48317794]]\n", + "\n", + " [[0.98375052 0.96953102 0.67860822 0.08797875 0.75146028]\n", + " [0.24008013 0.54515745 0.89102682 0.94231445 0.67131314]\n", + " [0.78124593 0.77789658 0.76329299 0.67676109 0.84266097]]]\n", + "[[[1.04481475 1.38985341 1.49217271 1.49457721 1.21676157]\n", + " [1.5156023 1.96249459 1.75039841 1.56715178 1.56133307]\n", + " [1.79692126 1.19150764 1.16139519 1.66684117 1.48317794]]\n", + "\n", + " [[1.98375052 1.96953102 1.67860822 1.08797875 1.75146028]\n", + " [1.24008013 1.54515745 1.89102682 1.94231445 1.67131314]\n", + " [1.78124593 1.77789658 1.76329299 1.67676109 1.84266097]]]\n" + ] + } + ], + "source": [ + "print(a)\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "The items of the matrix \"d\" is one unit more." + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.04481475 0.38985341 0.49217271 0.49457721 0.21676157]\n", + " [0.5156023 0.96249459 0.75039841 0.56715178 0.56133307]\n", + " [0.79692126 0.19150764 0.16139519 0.66684117 0.48317794]]\n", + "\n", + " [[0.98375052 0.96953102 0.67860822 0.08797875 0.75146028]\n", + " [0.24008013 0.54515745 0.89102682 0.94231445 0.67131314]\n", + " [0.78124593 0.77789658 0.76329299 0.67676109 0.84266097]]]\n" + ] + } + ], + "source": [ + "e = a*c\n", + "print(e)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Yes, it is equal because it is multiplied by 1." + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.983750518868177\n", + "1.0448147498937645\n", + "1.5966027113157943\n" + ] + } + ], + "source": [ + "d_max = numpy.amax(d)\n", + "print(d_max)\n", + "d_min = numpy.amin(d)\n", + "print(d_min)\n", + "d_mean = numpy.mean(d)\n", + "print(d_mean)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.04481475 0.38985341 0.49217271 0.49457721 0.21676157]\n", + " [0.5156023 0.96249459 0.75039841 0.56715178 0.56133307]\n", + " [0.79692126 0.19150764 0.16139519 0.66684117 0.48317794]]\n", + "\n", + " [[0.98375052 0.96953102 0.67860822 0.08797875 0.75146028]\n", + " [0.24008013 0.54515745 0.89102682 0.94231445 0.67131314]\n", + " [0.78124593 0.77789658 0.76329299 0.67676109 0.84266097]]]\n" + ] + } + ], + "source": [ + "f = numpy.empty([2,3,5])\n", + "print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 1.0448147498937645\n", + "1 1.3898534080526732\n", + "2 1.4921727080306226\n", + "3 1.4945772130914365\n", + "4 1.216761565944525\n", + "0 1.5156022998290024\n", + "1 1.9624945916975631\n", + "2 1.7503984126265975\n", + "3 1.5671517849784076\n", + "4 1.561333071601572\n", + "0 1.7969212602531952\n", + "1 1.1915076350063947\n", + "2 1.1613951923916253\n", + "3 1.6668411668239447\n", + "4 1.4831779416810331\n", + "0 1.983750518868177\n", + "1 1.969531018494684\n", + "2 1.6786082228834156\n", + "3 1.0879787464833446\n", + "4 1.7514602802143064\n", + "0 1.24008012685348\n", + "1 1.5451574469927516\n", + "2 1.8910268235125298\n", + "3 1.9423144465656903\n", + "4 1.6713131423002823\n", + "0 1.7812459253699091\n", + "1 1.7778965828219429\n", + "2 1.7632929912364417\n", + "3 1.676761090020392\n", + "4 1.8426609749541183\n" + ] + } + ], + "source": [ + "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\n", + "#print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1.04481475 1.38985341 1.49217271 1.49457721 1.21676157]\n", + " [1.5156023 1.96249459 1.75039841 1.56715178 1.56133307]\n", + " [1.79692126 1.19150764 1.16139519 1.66684117 1.48317794]]\n", + "\n", + " [[1.98375052 1.96953102 1.67860822 1.08797875 1.75146028]\n", + " [1.24008013 1.54515745 1.89102682 1.94231445 1.67131314]\n", + " [1.78124593 1.77789658 1.76329299 1.67676109 1.84266097]]]\n", + "[[[ 0. 25. 25. 25. 25.]\n", + " [ 25. 75. 75. 25. 25.]\n", + " [ 75. 25. 25. 75. 25.]]\n", + "\n", + " [[100. 75. 75. 25. 75.]\n", + " [ 25. 25. 75. 75. 75.]\n", + " [ 75. 75. 75. 75. 75.]]]\n" + ] + } + ], + "source": [ + "print(d)\n", + "print(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.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 1f767db6c617322078f0a148d5d1c7371d136fc1 Mon Sep 17 00:00:00 2001 From: KarenLizzette Date: Sat, 12 Oct 2019 16:48:17 -0500 Subject: [PATCH 2/2] Finished with bonus. --- .../main_code-checkpoint.ipynb | 83 +++++++++++++++++++ your-code/main_code.ipynb | 83 +++++++++++++++++++ 2 files changed, 166 insertions(+) diff --git a/your-code/.ipynb_checkpoints/main_code-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main_code-checkpoint.ipynb index 57dc94c..31551df 100644 --- a/your-code/.ipynb_checkpoints/main_code-checkpoint.ipynb +++ b/your-code/.ipynb_checkpoints/main_code-checkpoint.ipynb @@ -6,6 +6,8 @@ "metadata": {}, "outputs": [], "source": [ + "#1. Import the NUMPY package under the name np.\n", + "\n", "import numpy as numpy" ] }, @@ -26,6 +28,8 @@ } ], "source": [ + "#2. Print the NUMPY version and the configuration.\n", + "\n", "numpy.version.version" ] }, @@ -56,6 +60,9 @@ } ], "source": [ + "#3. Generate a 2x3x5 3-dimensional array with random values. Assign the array to variable \"a\"\n", + "#4. Print a.\n", + "\n", "a = numpy.random.random((2,3,5))\n", "print(a)\n", "\n", @@ -104,6 +111,10 @@ } ], "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 = numpy.full((5,2,3),1)\n", "print(b)\n", "\n", @@ -125,6 +136,8 @@ } ], "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", @@ -137,6 +150,8 @@ "metadata": {}, "outputs": [], "source": [ + "#8. Are you able to add a and b? Why or why not?\n", + "\n", "It does not work because the dimensions are different." ] }, @@ -160,6 +175,8 @@ } ], "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 = numpy.reshape(b,(2,3,5))\n", "print(c)" ] @@ -184,6 +201,8 @@ } ], "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)" ] @@ -224,6 +243,8 @@ } ], "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)" ] @@ -257,6 +278,8 @@ } ], "source": [ + "#12. Multiply a and c. Assign the result to e.\n", + "\n", "e = a*c\n", "print(e)" ] @@ -267,6 +290,8 @@ "metadata": {}, "outputs": [], "source": [ + "#13. Does e equal to a? Why or why not?\n", + "\n", "Yes, it is equal because it is multiplied by 1." ] }, @@ -286,6 +311,8 @@ } ], "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 = numpy.amax(d)\n", "print(d_max)\n", "d_min = numpy.amin(d)\n", @@ -314,6 +341,8 @@ } ], "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 = numpy.empty([2,3,5])\n", "print(f)" ] @@ -361,6 +390,14 @@ } ], "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", @@ -407,10 +444,56 @@ } ], "source": [ + "#17. Print d and f. Do you have your expected f?\n", + "\n", "print(d)\n", "print(f)" ] }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[['A' 'B' 'B' 'B' 'B']\n", + " ['B' 'D' 'D' 'B' 'B']\n", + " ['D' 'B' 'B' 'D' 'B']]\n", + "\n", + " [['E' 'D' 'D' 'B' 'D']\n", + " ['B' 'B' 'D' 'D' 'D']\n", + " ['D' 'D' 'D' 'D' '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 = numpy.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, diff --git a/your-code/main_code.ipynb b/your-code/main_code.ipynb index 57dc94c..31551df 100644 --- a/your-code/main_code.ipynb +++ b/your-code/main_code.ipynb @@ -6,6 +6,8 @@ "metadata": {}, "outputs": [], "source": [ + "#1. Import the NUMPY package under the name np.\n", + "\n", "import numpy as numpy" ] }, @@ -26,6 +28,8 @@ } ], "source": [ + "#2. Print the NUMPY version and the configuration.\n", + "\n", "numpy.version.version" ] }, @@ -56,6 +60,9 @@ } ], "source": [ + "#3. Generate a 2x3x5 3-dimensional array with random values. Assign the array to variable \"a\"\n", + "#4. Print a.\n", + "\n", "a = numpy.random.random((2,3,5))\n", "print(a)\n", "\n", @@ -104,6 +111,10 @@ } ], "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 = numpy.full((5,2,3),1)\n", "print(b)\n", "\n", @@ -125,6 +136,8 @@ } ], "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", @@ -137,6 +150,8 @@ "metadata": {}, "outputs": [], "source": [ + "#8. Are you able to add a and b? Why or why not?\n", + "\n", "It does not work because the dimensions are different." ] }, @@ -160,6 +175,8 @@ } ], "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 = numpy.reshape(b,(2,3,5))\n", "print(c)" ] @@ -184,6 +201,8 @@ } ], "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)" ] @@ -224,6 +243,8 @@ } ], "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)" ] @@ -257,6 +278,8 @@ } ], "source": [ + "#12. Multiply a and c. Assign the result to e.\n", + "\n", "e = a*c\n", "print(e)" ] @@ -267,6 +290,8 @@ "metadata": {}, "outputs": [], "source": [ + "#13. Does e equal to a? Why or why not?\n", + "\n", "Yes, it is equal because it is multiplied by 1." ] }, @@ -286,6 +311,8 @@ } ], "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 = numpy.amax(d)\n", "print(d_max)\n", "d_min = numpy.amin(d)\n", @@ -314,6 +341,8 @@ } ], "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 = numpy.empty([2,3,5])\n", "print(f)" ] @@ -361,6 +390,14 @@ } ], "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", @@ -407,10 +444,56 @@ } ], "source": [ + "#17. Print d and f. Do you have your expected f?\n", + "\n", "print(d)\n", "print(f)" ] }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[['A' 'B' 'B' 'B' 'B']\n", + " ['B' 'D' 'D' 'B' 'B']\n", + " ['D' 'B' 'B' 'D' 'B']]\n", + "\n", + " [['E' 'D' 'D' 'B' 'D']\n", + " ['B' 'B' 'D' 'D' 'D']\n", + " ['D' 'D' 'D' 'D' '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 = numpy.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,