diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 46f5aa1..0c22282 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -16,11 +16,11 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 1128, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "import numpy as np" ] }, { @@ -34,11 +34,94 @@ }, { "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": 1129, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"Compilers\": {\n", + " \"c\": {\n", + " \"name\": \"clang\",\n", + " \"linker\": \"ld64\",\n", + " \"version\": \"15.0.0\",\n", + " \"commands\": \"cc\"\n", + " },\n", + " \"cython\": {\n", + " \"name\": \"cython\",\n", + " \"linker\": \"cython\",\n", + " \"version\": \"3.0.11\",\n", + " \"commands\": \"cython\"\n", + " },\n", + " \"c++\": {\n", + " \"name\": \"clang\",\n", + " \"linker\": \"ld64\",\n", + " \"version\": \"15.0.0\",\n", + " \"commands\": \"c++\"\n", + " }\n", + " },\n", + " \"Machine Information\": {\n", + " \"host\": {\n", + " \"cpu\": \"aarch64\",\n", + " \"family\": \"aarch64\",\n", + " \"endian\": \"little\",\n", + " \"system\": \"darwin\"\n", + " },\n", + " \"build\": {\n", + " \"cpu\": \"aarch64\",\n", + " \"family\": \"aarch64\",\n", + " \"endian\": \"little\",\n", + " \"system\": \"darwin\"\n", + " }\n", + " },\n", + " \"Build Dependencies\": {\n", + " \"blas\": {\n", + " \"name\": \"accelerate\",\n", + " \"found\": true,\n", + " \"version\": \"unknown\",\n", + " \"detection method\": \"system\",\n", + " \"include directory\": \"unknown\",\n", + " \"lib directory\": \"unknown\",\n", + " \"openblas configuration\": \"unknown\",\n", + " \"pc file directory\": \"unknown\"\n", + " },\n", + " \"lapack\": {\n", + " \"name\": \"accelerate\",\n", + " \"found\": true,\n", + " \"version\": \"unknown\",\n", + " \"detection method\": \"system\",\n", + " \"include directory\": \"unknown\",\n", + " \"lib directory\": \"unknown\",\n", + " \"openblas configuration\": \"unknown\",\n", + " \"pc file directory\": \"unknown\"\n", + " }\n", + " },\n", + " \"Python Information\": {\n", + " \"path\": \"/private/var/folders/4d/0gnh84wj53j7wyk695q0tc_80000gn/T/build-env-kq4kuj35/bin/python\",\n", + " \"version\": \"3.9\"\n", + " },\n", + " \"SIMD Extensions\": {\n", + " \"baseline\": [\n", + " \"NEON\",\n", + " \"NEON_FP16\",\n", + " \"NEON_VFPV4\",\n", + " \"ASIMD\"\n", + " ],\n", + " \"found\": [\n", + " \"ASIMDHP\"\n", + " ],\n", + " \"not found\": [\n", + " \"ASIMDFHM\"\n", + " ]\n", + " }\n", + "}\n" + ] + } + ], + "source": [ + "np.show_config()" ] }, { @@ -51,11 +134,13 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 1130, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "a = np.random.rand(2,3,5)\n", + "\n", + "\n" ] }, { @@ -68,11 +153,25 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 1131, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.39656116 0.790648 0.88905418 0.40370293 0.00508151]\n", + " [0.11687306 0.64943981 0.9902077 0.67380398 0.07750517]\n", + " [0.95268089 0.27353551 0.45487337 0.16912848 0.38396048]]\n", + "\n", + " [[0.01002389 0.77195412 0.56544474 0.93345561 0.84118967]\n", + " [0.15204888 0.61848739 0.84714758 0.83790896 0.96659749]\n", + " [0.93322108 0.57602183 0.17063978 0.36075462 0.25446445]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "print(a)\n" ] }, { @@ -85,11 +184,11 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 1132, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "b = np.ones((5, 2, 3))\n" ] }, { @@ -102,11 +201,32 @@ }, { "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": 1133, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]]\n" + ] + } + ], + "source": [ + "print(b)" ] }, { @@ -119,11 +239,22 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 1134, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "They same\n" + ] + } + ], "source": [ - "### [your code here]\n" + "if a.size == b.size:\n", + " print('They same')\n", + "else:\n", + " print('they are not same')" ] }, { @@ -136,11 +267,23 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 1135, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Not possible as a and b are not having same shape\n" + ] + } + ], "source": [ - "### [your code here]\n" + "if a.shape == b.shape:\n", + " print('Adding is possible as they have same shape')\n", + "else:\n", + " print('Not possible as a and b are not having same shape')\n", + " \n" ] }, { @@ -154,11 +297,39 @@ }, { "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": null, + "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", + "[[[0.39656116 0.790648 0.88905418 0.40370293 0.00508151]\n", + " [0.11687306 0.64943981 0.9902077 0.67380398 0.07750517]\n", + " [0.95268089 0.27353551 0.45487337 0.16912848 0.38396048]]\n", + "\n", + " [[0.01002389 0.77195412 0.56544474 0.93345561 0.84118967]\n", + " [0.15204888 0.61848739 0.84714758 0.83790896 0.96659749]\n", + " [0.93322108 0.57602183 0.17063978 0.36075462 0.25446445]]]\n" + ] + } + ], + "source": [ + "#result should be: a = 2, 3, 5, so let's re-arrange axes:\n", + "#which original axis needs to move where?\n", + "# b = 5, 2, 3, so:\n", + "# 5 -> 1, 2 -> 2, 3 -> 0\n", + "c = np.transpose(b, (1, 2, 0))\n", + "\n", + "print(c)\n", + "print(a)" ] }, { @@ -171,11 +342,24 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 1137, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Adding is possible as they have same shape\n" + ] + } + ], "source": [ - "### [your code here]\n" + "#checking:\n", + "if a.shape == c.shape:\n", + " d = a + c\n", + " print('Adding is possible as they have same shape')\n", + "else:\n", + " print('Not possible as a and b are not having same shape')" ] }, { @@ -188,12 +372,34 @@ }, { "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n", - "\n" + "execution_count": 1138, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "array a: [[[0.39656116 0.790648 0.88905418 0.40370293 0.00508151]\n", + " [0.11687306 0.64943981 0.9902077 0.67380398 0.07750517]\n", + " [0.95268089 0.27353551 0.45487337 0.16912848 0.38396048]]\n", + "\n", + " [[0.01002389 0.77195412 0.56544474 0.93345561 0.84118967]\n", + " [0.15204888 0.61848739 0.84714758 0.83790896 0.96659749]\n", + " [0.93322108 0.57602183 0.17063978 0.36075462 0.25446445]]]\n", + "array d is a sum of a + d: [[[1.39656116 1.790648 1.88905418 1.40370293 1.00508151]\n", + " [1.11687306 1.64943981 1.9902077 1.67380398 1.07750517]\n", + " [1.95268089 1.27353551 1.45487337 1.16912848 1.38396048]]\n", + "\n", + " [[1.01002389 1.77195412 1.56544474 1.93345561 1.84118967]\n", + " [1.15204888 1.61848739 1.84714758 1.83790896 1.96659749]\n", + " [1.93322108 1.57602183 1.17063978 1.36075462 1.25446445]]]\n" + ] + } + ], + "source": [ + "print('array a:', a)\n", + "print('array d is a sum of a + d:', d)\n", + "#d is a sum of a + c" ] }, { @@ -206,11 +412,11 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 1139, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "e = a * c\n" ] }, { @@ -224,12 +430,41 @@ }, { "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n", - "\n" + "execution_count": 1140, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Adding is possible as they have same shape\n", + "array a: [[[0.39656116 0.790648 0.88905418 0.40370293 0.00508151]\n", + " [0.11687306 0.64943981 0.9902077 0.67380398 0.07750517]\n", + " [0.95268089 0.27353551 0.45487337 0.16912848 0.38396048]]\n", + "\n", + " [[0.01002389 0.77195412 0.56544474 0.93345561 0.84118967]\n", + " [0.15204888 0.61848739 0.84714758 0.83790896 0.96659749]\n", + " [0.93322108 0.57602183 0.17063978 0.36075462 0.25446445]]]\n", + "array e is a multiply of a * c, so 1 * 2 = 2: [[[1.39656116 1.790648 1.88905418 1.40370293 1.00508151]\n", + " [1.11687306 1.64943981 1.9902077 1.67380398 1.07750517]\n", + " [1.95268089 1.27353551 1.45487337 1.16912848 1.38396048]]\n", + "\n", + " [[1.01002389 1.77195412 1.56544474 1.93345561 1.84118967]\n", + " [1.15204888 1.61848739 1.84714758 1.83790896 1.96659749]\n", + " [1.93322108 1.57602183 1.17063978 1.36075462 1.25446445]]]\n" + ] + } + ], + "source": [ + "#checking:\n", + "if a.shape == e.shape:\n", + " result = a + e\n", + " print('Adding is possible as they have same shape')\n", + "else:\n", + " print('Not possible as a and b are not having same shape')\n", + " \n", + "print('array a:', a)\n", + "print('array e is a multiply of a * c, so 1 * 2 = 2:', d)" ] }, { @@ -243,12 +478,28 @@ }, { "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n", - "\n" + "execution_count": 1141, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max: 1.9902076999034497\n", + "Min: 1.0050815069240406\n", + "Mean: 1.5355472105084078\n" + ] + } + ], + "source": [ + "d_max = d.max()\n", + "d_min = d.min()\n", + "d_mean = d.mean()\n", + "\n", + "\n", + "print(\"Max:\", d_max)\n", + "print(\"Min:\", d_min)\n", + "print(\"Mean:\", d_mean)" ] }, { @@ -261,11 +512,13 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 1142, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "f = np.empty((2, 3, 5))\n", + "#or:\n", + "f = np.empty(d.shape)\n" ] }, { @@ -287,11 +540,41 @@ }, { "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ 25. 75. 75. 25. 0.]\n", + " [ 25. 75. 100. 75. 25.]\n", + " [ 75. 25. 25. 25. 25.]]\n", + "\n", + " [[ 25. 75. 75. 75. 75.]\n", + " [ 25. 75. 75. 75. 75.]\n", + " [ 75. 75. 25. 25. 25.]]]\n" + ] + } + ], + "source": [ + "for x in range(d.shape[0]): #go trough every layer\n", + " for z in range(d.shape[1]): #go trough every row\n", + " for y in range(d.shape[2]): #go trough every column\n", + " \n", + " value = d[x][z][y] #pull out the number that lives on layer x, row z, column y\n", + " \n", + " if value == d_min:\n", + " f[x][z][y] = 0\n", + " elif value == d_max:\n", + " f[x][z][y] = 100\n", + " elif value == d_mean:\n", + " f[x][z][y] = 50\n", + " elif d_min < value < d_mean:\n", + " f[x][z][y] = 25\n", + " elif d_mean < value < d_max:\n", + " f[x][z][y] = 75\n", + "print(f)" ] }, { @@ -325,11 +608,34 @@ }, { "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [], + "execution_count": 1144, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "here is d: [[[1.39656116 1.790648 1.88905418 1.40370293 1.00508151]\n", + " [1.11687306 1.64943981 1.9902077 1.67380398 1.07750517]\n", + " [1.95268089 1.27353551 1.45487337 1.16912848 1.38396048]]\n", + "\n", + " [[1.01002389 1.77195412 1.56544474 1.93345561 1.84118967]\n", + " [1.15204888 1.61848739 1.84714758 1.83790896 1.96659749]\n", + " [1.93322108 1.57602183 1.17063978 1.36075462 1.25446445]]]\n", + "here is f: [[[ 25. 75. 75. 25. 0.]\n", + " [ 25. 75. 100. 75. 25.]\n", + " [ 75. 25. 25. 25. 25.]]\n", + "\n", + " [[ 25. 75. 75. 75. 75.]\n", + " [ 25. 75. 75. 75. 75.]\n", + " [ 75. 75. 25. 25. 25.]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "print('here is d:', d)\n", + "print('here is f:', f)" ] }, { @@ -350,7 +656,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 1145, "metadata": {}, "outputs": [], "source": [ @@ -360,7 +666,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -374,7 +680,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.0" + "version": "3.9.6" } }, "nbformat": 4,