diff --git a/NumPy - Basics/NumPy - Basics.ipynb b/NumPy - Basics/NumPy - Basics.ipynb index 5f0795dbf9..5e89118b91 100644 --- a/NumPy - Basics/NumPy - Basics.ipynb +++ b/NumPy - Basics/NumPy - Basics.ipynb @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 2, "id": "684810d6", "metadata": {}, "outputs": [ @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 3, "id": "95c01a0f", "metadata": {}, "outputs": [ @@ -70,7 +70,7 @@ "1" ] }, - "execution_count": 8, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -82,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 4, "id": "ff246807", "metadata": {}, "outputs": [ @@ -92,7 +92,7 @@ "(5,)" ] }, - "execution_count": 9, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -104,7 +104,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 5, "id": "4cf047d3", "metadata": {}, "outputs": [ @@ -114,7 +114,7 @@ "dtype('int32')" ] }, - "execution_count": 10, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -126,7 +126,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 6, "id": "bb10741e", "metadata": {}, "outputs": [ @@ -136,7 +136,7 @@ "5" ] }, - "execution_count": 11, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -156,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 7, "id": "eb40e2f9", "metadata": {}, "outputs": [], @@ -167,7 +167,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, "id": "51fa97c1", "metadata": {}, "outputs": [ @@ -185,7 +185,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 9, "id": "cf1807c1", "metadata": {}, "outputs": [ @@ -195,7 +195,7 @@ "numpy.ndarray" ] }, - "execution_count": 4, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -214,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "id": "a2f3276d", "metadata": {}, "outputs": [ @@ -252,7 +252,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "id": "41356018", "metadata": {}, "outputs": [ @@ -262,7 +262,7 @@ "array([4, 6, 3, 8])" ] }, - "execution_count": 14, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -273,7 +273,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "id": "f9032bfc", "metadata": {}, "outputs": [ @@ -283,7 +283,7 @@ "3" ] }, - "execution_count": 13, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -295,7 +295,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 13, "id": "a5d10c99", "metadata": {}, "outputs": [ @@ -305,7 +305,7 @@ "array([4, 6])" ] }, - "execution_count": 16, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -325,7 +325,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 14, "id": "1b862570", "metadata": {}, "outputs": [ @@ -337,7 +337,7 @@ " [7, 8, 9]])" ] }, - "execution_count": 17, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -346,9 +346,17 @@ "md_arr" ] }, + { + "cell_type": "markdown", + "id": "1a203231-f28c-4d9e-a2b2-4f34246fb95d", + "metadata": {}, + "source": [ + "### Slicing arrays:" + ] + }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 15, "id": "ccf30da0", "metadata": {}, "outputs": [ @@ -358,7 +366,7 @@ "6" ] }, - "execution_count": 18, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -370,7 +378,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 16, "id": "549c5bca", "metadata": {}, "outputs": [ @@ -380,7 +388,7 @@ "array([7, 8, 9])" ] }, - "execution_count": 22, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -392,7 +400,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 17, "id": "3218c148", "metadata": {}, "outputs": [ @@ -402,7 +410,7 @@ "array([2, 5, 8])" ] }, - "execution_count": 21, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -414,7 +422,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 18, "id": "4c7c5f68", "metadata": {}, "outputs": [ @@ -435,6 +443,231 @@ "print(md_arr)" ] }, + { + "cell_type": "markdown", + "id": "9003f64c-3d8c-429a-9872-16de658ab309", + "metadata": {}, + "source": [ + "#### Concatenation of arrays" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "08ed59b0-ca59-460f-a6a3-3ffc3be302dc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([1, 2, 3, 3, 2, 1])" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = np.array([1,2,3])\n", + "y = np.array([3,2,1])\n", + "np.concatenate([x,y])" + ] + }, + { + "cell_type": "markdown", + "id": "fbca3a78-a928-4abd-83da-785e30d66b98", + "metadata": {}, + "source": [ + "### Arithmetic Operations" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "33e2aabe-9deb-4c1c-abe7-d2a3a54fcf3f", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([4, 4, 4])" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#add two arrays\n", + "add = np.add(x,y)\n", + "add" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "0886816d-a4eb-4192-a80b-6fae2bbe8539", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-2, 0, 2])" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#subtract two arrays\n", + "sub =np.subtract(x,y)\n", + "sub" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "98ade084-cd4c-468a-8576-03410f62d3ad", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-1, -2, -3])" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#unary negation\n", + "neg=np.negative(x)\n", + "neg" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "a65693fb-4200-4ce2-a6aa-250813e7a395", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([3, 4, 3])" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#multiply two arrays\n", + "prod = np.multiply(x,y)\n", + "prod" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "0bf23e73-2a68-42a3-b7d2-2b2408b35d73", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([0.33333333, 1. , 3. ])" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#divide two arrays\n", + "div = np.divide(x,y)\n", + "div" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "1df89079-fede-4f88-9173-43318018aba9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([0, 1, 3])" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#floor division of two arrays\n", + "floordiv = np.floor_divide(x,y)\n", + "floordiv" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "2f8923cd-e8c7-4f62-ad01-05f595b8c6a3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#exponentiation\n", + "power = np.power(2,3)\n", + "power" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "40c63d50-5474-4e68-b265-8ac98e03ad0c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#modulus\n", + "mod = np.mod(9,4)\n", + "mod" + ] + }, { "cell_type": "markdown", "id": "6a3d5861", @@ -453,7 +686,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 28, "id": "86a41bc2", "metadata": {}, "outputs": [ @@ -463,7 +696,7 @@ "array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])" ] }, - "execution_count": 25, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -475,7 +708,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 29, "id": "b337bbb9", "metadata": {}, "outputs": [ @@ -485,7 +718,7 @@ "array([ 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14.])" ] }, - "execution_count": 26, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -497,7 +730,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 30, "id": "34aa02f9", "metadata": {}, "outputs": [ @@ -507,7 +740,7 @@ "array([ 1, 4, 7, 10, 13])" ] }, - "execution_count": 28, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -528,7 +761,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 31, "id": "8c8c7eda", "metadata": {}, "outputs": [ @@ -538,7 +771,7 @@ "array([0. , 0.25, 0.5 , 0.75, 1. ])" ] }, - "execution_count": 38, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -549,7 +782,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 32, "id": "64501cb7", "metadata": {}, "outputs": [ @@ -559,7 +792,7 @@ "array([1. , 1.5, 2. , 2.5, 3. , 3.5])" ] }, - "execution_count": 39, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -579,7 +812,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 33, "id": "8042c4fe", "metadata": {}, "outputs": [], @@ -591,7 +824,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 34, "id": "6e0a31b1", "metadata": {}, "outputs": [ @@ -601,7 +834,7 @@ "(2, 3)" ] }, - "execution_count": 31, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -680,7 +913,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 38, "id": "44151a83", "metadata": {}, "outputs": [ @@ -690,7 +923,7 @@ "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])" ] }, - "execution_count": 40, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -701,7 +934,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 39, "id": "29a9291f", "metadata": {}, "outputs": [ @@ -714,7 +947,7 @@ " [0., 0., 0.]])" ] }, - "execution_count": 42, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -725,7 +958,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 40, "id": "b82b842e", "metadata": {}, "outputs": [ @@ -738,7 +971,7 @@ " [0, 0, 0]])" ] }, - "execution_count": 43, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } @@ -757,7 +990,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 41, "id": "56a695dc", "metadata": {}, "outputs": [ @@ -767,7 +1000,7 @@ "array([1., 1., 1., 1., 1.])" ] }, - "execution_count": 44, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -778,7 +1011,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 42, "id": "b5aa24ee", "metadata": {}, "outputs": [ @@ -789,7 +1022,7 @@ " [1., 1., 1., 1., 1.]])" ] }, - "execution_count": 45, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -800,7 +1033,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 43, "id": "4c0b6e5d", "metadata": {}, "outputs": [ @@ -814,7 +1047,7 @@ " [1, 1]])" ] }, - "execution_count": 46, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -833,7 +1066,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 44, "id": "26fd2068", "metadata": {}, "outputs": [ @@ -843,7 +1076,7 @@ "array([0.25, 0.5 , 0.75, 1. ])" ] }, - "execution_count": 47, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -854,19 +1087,19 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 45, "id": "4650214e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[ 1, 1, 0],\n", - " [1936682280, 344, 0],\n", - " [ 16777984, 459, 573142131]])" + "array([[ 0, 0, 279203168],\n", + " [ 267, 279204048, 267],\n", + " [279202128, 267, 7929957]])" ] }, - "execution_count": 49, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } @@ -885,7 +1118,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 46, "id": "89f8704e", "metadata": {}, "outputs": [ @@ -898,7 +1131,7 @@ " [0., 0., 0., 1.]])" ] }, - "execution_count": 50, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } @@ -909,7 +1142,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 47, "id": "b2321259", "metadata": {}, "outputs": [ @@ -922,7 +1155,7 @@ " [0, 0, 0, 1]])" ] }, - "execution_count": 53, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -941,7 +1174,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 48, "id": "e08b35a1", "metadata": {}, "outputs": [ @@ -952,7 +1185,7 @@ " [0., 1.]])" ] }, - "execution_count": 54, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } @@ -963,7 +1196,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 49, "id": "1e669687", "metadata": {}, "outputs": [ @@ -980,7 +1213,7 @@ " [0., 0., 0., 0.]])" ] }, - "execution_count": 55, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -991,7 +1224,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 50, "id": "39298f43", "metadata": {}, "outputs": [ @@ -1008,7 +1241,7 @@ " [0, 0, 0, 0]])" ] }, - "execution_count": 57, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -1027,17 +1260,17 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 51, "id": "5c5ed1ed", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([0.96844061, 0.04042306, 0.287759 ])" + "array([0.3812388 , 0.03651375, 0.34331775])" ] }, - "execution_count": 58, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } @@ -1048,17 +1281,17 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 52, "id": "2e024ab5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([-1.68800733, 0.69039249])" + "array([ 0.61284422, -0.07029641])" ] }, - "execution_count": 59, + "execution_count": 52, "metadata": {}, "output_type": "execute_result" } @@ -1069,18 +1302,18 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 53, "id": "9f93753b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[0.88905109, 0.23563943, 0.57782012, 0.74340422, 0.88435015],\n", - " [0.79799881, 0.71703718, 0.7145446 , 0.54194783, 0.76422077]])" + "array([[0.10587568, 0.14647444, 0.01860027, 0.78634316, 0.74404556],\n", + " [0.19103123, 0.03814603, 0.08133144, 0.59476043, 0.82063691]])" ] }, - "execution_count": 60, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -1099,7 +1332,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 54, "id": "cad51f50", "metadata": {}, "outputs": [ @@ -1128,7 +1361,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 55, "id": "8facee2d", "metadata": {}, "outputs": [], @@ -1141,7 +1374,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 56, "id": "07445b34", "metadata": {}, "outputs": [], @@ -1154,7 +1387,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 57, "id": "f659834b", "metadata": {}, "outputs": [ @@ -1166,7 +1399,7 @@ " [105, 98]])" ] }, - "execution_count": 65, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } @@ -1177,7 +1410,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 58, "id": "8eea6d9e", "metadata": {}, "outputs": [ @@ -1189,7 +1422,7 @@ " [105, 98]])" ] }, - "execution_count": 66, + "execution_count": 58, "metadata": {}, "output_type": "execute_result" } @@ -1201,7 +1434,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 59, "id": "5d0a0817", "metadata": {}, "outputs": [ @@ -1212,7 +1445,7 @@ " [2, 6, 4]])" ] }, - "execution_count": 67, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -1232,7 +1465,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 60, "id": "e159041d", "metadata": {}, "outputs": [], @@ -1243,7 +1476,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 61, "id": "437a7435", "metadata": {}, "outputs": [ @@ -1253,7 +1486,7 @@ "22" ] }, - "execution_count": 69, + "execution_count": 61, "metadata": {}, "output_type": "execute_result" } @@ -1265,7 +1498,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 62, "id": "363f3cb1", "metadata": {}, "outputs": [ @@ -1275,7 +1508,7 @@ "1.8547236990991407" ] }, - "execution_count": 70, + "execution_count": 62, "metadata": {}, "output_type": "execute_result" } @@ -1287,7 +1520,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 63, "id": "2a7071ae", "metadata": {}, "outputs": [ @@ -1297,7 +1530,7 @@ "3.44" ] }, - "execution_count": 71, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } @@ -1309,7 +1542,7 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 64, "id": "60868fc9", "metadata": {}, "outputs": [], @@ -1323,7 +1556,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 65, "id": "d4f89544", "metadata": {}, "outputs": [ @@ -1333,7 +1566,7 @@ "24" ] }, - "execution_count": 77, + "execution_count": 65, "metadata": {}, "output_type": "execute_result" } @@ -1344,7 +1577,7 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 66, "id": "2c2b2d2c", "metadata": {}, "outputs": [ @@ -1354,7 +1587,7 @@ "4.0" ] }, - "execution_count": 78, + "execution_count": 66, "metadata": {}, "output_type": "execute_result" } @@ -1365,7 +1598,7 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": 67, "id": "5093c278", "metadata": {}, "outputs": [ @@ -1375,7 +1608,7 @@ "1.9148542155126762" ] }, - "execution_count": 79, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } @@ -1386,7 +1619,7 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 68, "id": "7ef88949", "metadata": {}, "outputs": [ @@ -1396,7 +1629,7 @@ "array([ 5, 7, 12])" ] }, - "execution_count": 80, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } @@ -1405,19 +1638,11 @@ "#sum of elements of columns\n", "A.sum(axis=0)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "599611eb", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -1431,7 +1656,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.10" + "version": "3.12.3" } }, "nbformat": 4,