diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 46f5aa14..b0376454 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -16,11 +16,12 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "import numpy as np" ] }, { @@ -34,11 +35,20 @@ }, { "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.24.3\n" + ] + } + ], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "print(np.__version__)" ] }, { @@ -51,11 +61,14 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "a = np.random.randint(0, 100, size=(2, 3, 5))\n", + "a = np.random.random(size=(2, 3, 5))\n", + "a = np.random.randn(2, 3, 5)" ] }, { @@ -68,11 +81,26 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ 1.21960083 1.18213398 0.43255391 -0.04081272 1.06483641]\n", + " [-1.25767305 1.3818794 0.67062811 0.68605796 -0.89579675]\n", + " [ 1.67443856 -1.67271859 0.84217768 0.85273045 -1.20262247]]\n", + "\n", + " [[-0.38037238 0.17981965 -0.62973536 1.3031449 0.70061514]\n", + " [ 0.31004281 0.98138047 -0.48544696 0.63113993 -1.84137843]\n", + " [-1.60335515 1.64832656 1.72835861 -1.21264931 -0.19798975]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "print(a)" ] }, { @@ -85,11 +113,12 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "b=np.ones((5, 2, 3))" ] }, { @@ -102,11 +131,33 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 27, "metadata": {}, - "outputs": [], + "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": [ - "### [your code here]\n" + "### [your code here]\n", + "print(b)" ] }, { @@ -119,11 +170,22 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(2, 3, 5)\n", + "(5, 2, 3)\n" + ] + } + ], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "print(a.shape)\n", + "print(b.shape)" ] }, { @@ -136,11 +198,25 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ValueError", + "evalue": "operands could not be broadcast together with shapes (2,3,5) (5,2,3) ", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "Input \u001b[1;32mIn [34]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m### [your code here]\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[43ma\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43mb\u001b[49m\n", + "\u001b[1;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,3,5) (5,2,3) " + ] + } + ], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "a+b\n", + "# NumPy tried to line up the dimensions of a and b, but they don’t match in a way that allows broadcasting." ] }, { @@ -154,11 +230,29 @@ }, { "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [], + "execution_count": 37, + "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", + "(2, 3, 5)\n" + ] + } + ], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "c=b.reshape((2,3,5))\n", + "print(c)\n", + "print(c.shape)" ] }, { @@ -171,11 +265,29 @@ }, { "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [], + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ 2.21960083 2.18213398 1.43255391 0.95918728 2.06483641]\n", + " [-0.25767305 2.3818794 1.67062811 1.68605796 0.10420325]\n", + " [ 2.67443856 -0.67271859 1.84217768 1.85273045 -0.20262247]]\n", + "\n", + " [[ 0.61962762 1.17981965 0.37026464 2.3031449 1.70061514]\n", + " [ 1.31004281 1.98138047 0.51455304 1.63113993 -0.84137843]\n", + " [-0.60335515 2.64832656 2.72835861 -0.21264931 0.80201025]]]\n", + "(2, 3, 5)\n" + ] + } + ], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "d=a+c\n", + "print(d)\n", + "print(d.shape)" ] }, { @@ -188,12 +300,35 @@ }, { "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [], + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ 1.21960083 1.18213398 0.43255391 -0.04081272 1.06483641]\n", + " [-1.25767305 1.3818794 0.67062811 0.68605796 -0.89579675]\n", + " [ 1.67443856 -1.67271859 0.84217768 0.85273045 -1.20262247]]\n", + "\n", + " [[-0.38037238 0.17981965 -0.62973536 1.3031449 0.70061514]\n", + " [ 0.31004281 0.98138047 -0.48544696 0.63113993 -1.84137843]\n", + " [-1.60335515 1.64832656 1.72835861 -1.21264931 -0.19798975]]]\n", + "[[[ 2.21960083 2.18213398 1.43255391 0.95918728 2.06483641]\n", + " [-0.25767305 2.3818794 1.67062811 1.68605796 0.10420325]\n", + " [ 2.67443856 -0.67271859 1.84217768 1.85273045 -0.20262247]]\n", + "\n", + " [[ 0.61962762 1.17981965 0.37026464 2.3031449 1.70061514]\n", + " [ 1.31004281 1.98138047 0.51455304 1.63113993 -0.84137843]\n", + " [-0.60335515 2.64832656 2.72835861 -0.21264931 0.80201025]]]\n" + ] + } + ], "source": [ "### [your code here]\n", - "\n" + "print(a)\n", + "print(d)\n", + "# The difference is that every value in array d is equal to the corresponding value in array a plus 1.If we subtract 1 from array d, we get back array a." ] }, { @@ -206,11 +341,27 @@ }, { "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [], + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ 1.21960083 1.18213398 0.43255391 -0.04081272 1.06483641]\n", + " [-1.25767305 1.3818794 0.67062811 0.68605796 -0.89579675]\n", + " [ 1.67443856 -1.67271859 0.84217768 0.85273045 -1.20262247]]\n", + "\n", + " [[-0.38037238 0.17981965 -0.62973536 1.3031449 0.70061514]\n", + " [ 0.31004281 0.98138047 -0.48544696 0.63113993 -1.84137843]\n", + " [-1.60335515 1.64832656 1.72835861 -1.21264931 -0.19798975]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "e =a*c\n", + "print(e)" ] }, { @@ -224,12 +375,27 @@ }, { "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [], + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ True True True True True]\n", + " [ True True True True True]\n", + " [ True True True True True]]\n", + "\n", + " [[ True True True True True]\n", + " [ True True True True True]\n", + " [ True True True True True]]]\n" + ] + } + ], "source": [ "### [your code here]\n", - "\n" + "print(e==a)\n", + "# both are equal becuase we are multiply c of ones to a which will resulted e also resulted e" ] }, { @@ -243,12 +409,24 @@ }, { "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [], + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max Value: 2.7283586057779545\n", + "Min Value: -0.8413784332340619\n", + "Mean Value: 1.202310480778084\n" + ] + } + ], "source": [ "### [your code here]\n", - "\n" + "d_max = np.max(d); print(\"Max Value:\", d_max);\n", + "d_min = np.min(d); print(\"Min Value:\", d_min);\n", + "d_mean = np.mean(d);print(\"Mean Value:\", d_mean);" ] }, { @@ -261,11 +439,30 @@ }, { "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [], - "source": [ - "### [your code here]\n" + "execution_count": 63, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[2.21960083 2.18213398 1.43255391 0.95918728 2.06483641]\n", + " [0.25767305 2.3818794 1.67062811 1.68605796 0.10420325]\n", + " [2.67443856 0.67271859 1.84217768 1.85273045 0.20262247]]\n", + "\n", + " [[0.61962762 1.17981965 0.37026464 2.3031449 1.70061514]\n", + " [1.31004281 1.98138047 0.51455304 1.63113993 0.84137843]\n", + " [0.60335515 2.64832656 2.72835861 0.21264931 0.80201025]]]\n", + "(2, 3, 5)\n" + ] + } + ], + "source": [ + "f = np.empty(d.shape)\n", + "print(f)\n", + "print(f.shape)" ] }, { @@ -287,11 +484,27 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 64, "metadata": {}, "outputs": [], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "d_list = d.tolist()\n", + "f = [[[0 for k in range(5)] for j in range(3)] for i in range(2)]\n", + "for i in range(len(d_list)): # first dimension\n", + " for j in range(len(d_list[i])): # second dimension\n", + " for k in range(len(d_list[i][j])): # third dimension\n", + " value = d_list[i][j][k]\n", + " if value == d_min:\n", + " f[i][j][k] = 0\n", + " elif value == d_max:\n", + " f[i][j][k] = 100\n", + " elif value == d_mean:\n", + " f[i][j][k] = 50\n", + " elif value > d_min and value < d_mean:\n", + " f[i][j][k] = 25\n", + " elif value > d_mean and value < d_max:\n", + " f[i][j][k] = 75\n" ] }, { @@ -325,11 +538,28 @@ }, { "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [], + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[ 2.21960083 2.18213398 1.43255391 0.95918728 2.06483641]\n", + " [-0.25767305 2.3818794 1.67062811 1.68605796 0.10420325]\n", + " [ 2.67443856 -0.67271859 1.84217768 1.85273045 -0.20262247]]\n", + "\n", + " [[ 0.61962762 1.17981965 0.37026464 2.3031449 1.70061514]\n", + " [ 1.31004281 1.98138047 0.51455304 1.63113993 -0.84137843]\n", + " [-0.60335515 2.64832656 2.72835861 -0.21264931 0.80201025]]]\n", + "[[[75, 75, 75, 25, 75], [25, 75, 75, 75, 25], [75, 25, 75, 75, 25]], [[25, 25, 25, 75, 75], [75, 75, 25, 75, 0], [25, 75, 100, 25, 25]]]\n" + ] + } + ], "source": [ - "### [your code here]\n" + "### [your code here]\n", + "print(d)\n", + "print(f)" ] }, { @@ -350,17 +580,58 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 66, "metadata": {}, "outputs": [], "source": [ - "### [your code here]" + "### [your code here]\n", + "### [your code here]\n", + "d_list = d.tolist()\n", + "f = [[[0 for k in range(5)] for j in range(3)] for i in range(2)]\n", + "for i in range(len(d_list)): # first dimension\n", + " for j in range(len(d_list[i])): # second dimension\n", + " for k in range(len(d_list[i][j])): # third dimension\n", + " value = d_list[i][j][k]\n", + " if value == d_min:\n", + " f[i][j][k] = \"A\"\n", + " elif value == d_max:\n", + " f[i][j][k] = \"E\"\n", + " elif value == d_mean:\n", + " f[i][j][k] = \"C\"\n", + " elif value > d_min and value < d_mean:\n", + " f[i][j][k] = \"B\"\n", + " elif value > d_mean and value < d_max:\n", + " f[i][j][k] = \"D\"" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[['D', 'D', 'D', 'B', 'D'], ['B', 'D', 'D', 'D', 'B'], ['D', 'B', 'D', 'D', 'B']], [['B', 'B', 'B', 'D', 'D'], ['D', 'D', 'B', 'D', 'A'], ['B', 'D', 'E', 'B', 'B']]]\n" + ] + } + ], + "source": [ + "print(f)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -374,7 +645,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.0" + "version": "3.9.12" } }, "nbformat": 4,