diff --git a/_images/gradient-descent_19_1.png b/_images/gradient-descent_19_1.png index f5d75774d..36cd0b2ba 100644 Binary files a/_images/gradient-descent_19_1.png and b/_images/gradient-descent_19_1.png differ diff --git a/_images/kernel-method_32_0.png b/_images/kernel-method_32_0.png index bb25c20e7..9620e2f56 100644 Binary files a/_images/kernel-method_32_0.png and b/_images/kernel-method_32_0.png differ diff --git a/_images/kernel-method_39_1.png b/_images/kernel-method_39_1.png index f3404a97f..52ec2b26d 100644 Binary files a/_images/kernel-method_39_1.png and b/_images/kernel-method_39_1.png differ diff --git a/_images/tools-of-the-trade_29_0.png b/_images/tools-of-the-trade_29_0.png index ce0236f7e..07bada16d 100644 Binary files a/_images/tools-of-the-trade_29_0.png and b/_images/tools-of-the-trade_29_0.png differ diff --git a/_images/visualization-relationships_12_0.png b/_images/visualization-relationships_12_0.png index 814c2b362..7a6cde5af 100644 Binary files a/_images/visualization-relationships_12_0.png and b/_images/visualization-relationships_12_0.png differ diff --git a/_images/visualization-relationships_16_0.png b/_images/visualization-relationships_16_0.png index 778d0ded5..95c0e7590 100644 Binary files a/_images/visualization-relationships_16_0.png and b/_images/visualization-relationships_16_0.png differ diff --git a/_images/visualization-relationships_18_1.png b/_images/visualization-relationships_18_1.png index da526cb9a..b56a1cc81 100644 Binary files a/_images/visualization-relationships_18_1.png and b/_images/visualization-relationships_18_1.png differ diff --git a/_images/visualization-relationships_20_0.png b/_images/visualization-relationships_20_0.png index 60df73848..b2c3086f6 100644 Binary files a/_images/visualization-relationships_20_0.png and b/_images/visualization-relationships_20_0.png differ diff --git a/_sources/assignments/ml-fundamentals/create-a-regression-model.ipynb b/_sources/assignments/ml-fundamentals/create-a-regression-model.ipynb index d49d239e4..4356f6dc7 100644 --- a/_sources/assignments/ml-fundamentals/create-a-regression-model.ipynb +++ b/_sources/assignments/ml-fundamentals/create-a-regression-model.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "e20d2edc", + "id": "7f8c5d9c", "metadata": {}, "source": [ "# Create a regression model\n", diff --git a/_sources/assignments/ml-fundamentals/exploring-visualizations.ipynb b/_sources/assignments/ml-fundamentals/exploring-visualizations.ipynb index b8893c0c2..28b6e7d61 100644 --- a/_sources/assignments/ml-fundamentals/exploring-visualizations.ipynb +++ b/_sources/assignments/ml-fundamentals/exploring-visualizations.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "c6ca74f8", + "id": "54030063", "metadata": {}, "source": [ "# Exploring visualizations\n", diff --git a/_sources/assignments/ml-fundamentals/parameter-play.ipynb b/_sources/assignments/ml-fundamentals/parameter-play.ipynb index 452254a70..df47a8e2f 100644 --- a/_sources/assignments/ml-fundamentals/parameter-play.ipynb +++ b/_sources/assignments/ml-fundamentals/parameter-play.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "bab39da2", + "id": "1407fd89", "metadata": {}, "source": [ "# Parameter play\n", diff --git a/_sources/assignments/ml-fundamentals/regression-with-scikit-learn.ipynb b/_sources/assignments/ml-fundamentals/regression-with-scikit-learn.ipynb index 029508848..9ea709ddd 100644 --- a/_sources/assignments/ml-fundamentals/regression-with-scikit-learn.ipynb +++ b/_sources/assignments/ml-fundamentals/regression-with-scikit-learn.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "f7adfd63", + "id": "6f86010f", "metadata": {}, "source": [ "# Regression with Scikit-learn\n", diff --git a/_sources/assignments/ml-fundamentals/retrying-some-regression.ipynb b/_sources/assignments/ml-fundamentals/retrying-some-regression.ipynb index e26202a53..a8a8404cd 100644 --- a/_sources/assignments/ml-fundamentals/retrying-some-regression.ipynb +++ b/_sources/assignments/ml-fundamentals/retrying-some-regression.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "5746f76c", + "id": "63285526", "metadata": {}, "source": [ "# Retrying some regression\n", diff --git a/_sources/data-science/working-with-data/numpy.ipynb b/_sources/data-science/working-with-data/numpy.ipynb index c53a46ca1..3b38e3b08 100644 --- a/_sources/data-science/working-with-data/numpy.ipynb +++ b/_sources/data-science/working-with-data/numpy.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "d42f9283", + "id": "b5888482", "metadata": {}, "source": [ "# NumPy\n", @@ -19,7 +19,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "fc137a63", + "id": "785cda3a", "metadata": {}, "outputs": [ { @@ -40,7 +40,7 @@ }, { "cell_type": "markdown", - "id": "24ccb95d", + "id": "4497576e", "metadata": {}, "source": [ "### Create a basic array\n", @@ -53,7 +53,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "60efb52b", + "id": "a102ea7f", "metadata": {}, "outputs": [ { @@ -75,7 +75,7 @@ }, { "cell_type": "markdown", - "id": "79fb360b", + "id": "45e91322", "metadata": {}, "source": [ "Besides creating an array from a sequence of elements, you can easily create an array filled with `0`’s:" @@ -84,7 +84,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "87056673", + "id": "dfe4c7a0", "metadata": {}, "outputs": [ { @@ -104,7 +104,7 @@ }, { "cell_type": "markdown", - "id": "ed96c79b", + "id": "03a6c41b", "metadata": {}, "source": [ "Or an array filled with 1’s:" @@ -113,7 +113,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "00a180bf", + "id": "30524d08", "metadata": {}, "outputs": [ { @@ -133,7 +133,7 @@ }, { "cell_type": "markdown", - "id": "ae3d7d40", + "id": "ebf9858c", "metadata": {}, "source": [ "Or even an empty array! The function `empty` creates an array whose initial content is random and depends on the state of the memory. The reason to use `empty` over `zeros` (or something similar) is speed - just make sure to fill every element afterwards!" @@ -142,7 +142,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "2a4d1f70", + "id": "4e02ccfd", "metadata": {}, "outputs": [ { @@ -162,7 +162,7 @@ }, { "cell_type": "markdown", - "id": "17cd44f8", + "id": "3dbd97c7", "metadata": {}, "source": [ "You can create an array with a range of elements:" @@ -171,7 +171,7 @@ { "cell_type": "code", "execution_count": 6, - "id": "a6c9eb69", + "id": "a0448381", "metadata": {}, "outputs": [ { @@ -191,7 +191,7 @@ }, { "cell_type": "markdown", - "id": "97fe4079", + "id": "47cada4e", "metadata": {}, "source": [ "And even an array that contains a range of evenly spaced intervals. To do this, you will specify the **first number**, **last number**, and the **step size**." @@ -200,7 +200,7 @@ { "cell_type": "code", "execution_count": 7, - "id": "3a9ee670", + "id": "05de6608", "metadata": {}, "outputs": [ { @@ -220,7 +220,7 @@ }, { "cell_type": "markdown", - "id": "43e227b2", + "id": "69708ef5", "metadata": {}, "source": [ "You can also use `np.linspace()` to create an array with values that are spaced linearly in a specified interval:" @@ -229,7 +229,7 @@ { "cell_type": "code", "execution_count": 8, - "id": "973239b9", + "id": "73c75e6d", "metadata": {}, "outputs": [ { @@ -249,7 +249,7 @@ }, { "cell_type": "markdown", - "id": "20e1dd2c", + "id": "d4ed5418", "metadata": {}, "source": [ "While the default data type is floating point (`np.float64`), you can explicitly specify which data type you want using the `dtype` keyword." @@ -258,7 +258,7 @@ { "cell_type": "code", "execution_count": 9, - "id": "0fb481ef", + "id": "03b5f43a", "metadata": {}, "outputs": [ { @@ -278,7 +278,7 @@ }, { "cell_type": "markdown", - "id": "041ef39d", + "id": "e5709a38", "metadata": {}, "source": [ "### Adding, removing, and sorting elements\n", @@ -291,7 +291,7 @@ { "cell_type": "code", "execution_count": 10, - "id": "aed933a7", + "id": "049e020a", "metadata": {}, "outputs": [], "source": [ @@ -300,7 +300,7 @@ }, { "cell_type": "markdown", - "id": "37d480ec", + "id": "be71fbe1", "metadata": {}, "source": [ "You can quickly sort the numbers in ascending order with:" @@ -309,7 +309,7 @@ { "cell_type": "code", "execution_count": 11, - "id": "93ec8ca4", + "id": "de2aa8cf", "metadata": {}, "outputs": [ { @@ -329,7 +329,7 @@ }, { "cell_type": "markdown", - "id": "b5a0feff", + "id": "d6849175", "metadata": {}, "source": [ "In addition to sort, which returns a sorted copy of an array, you can use:\n", @@ -345,7 +345,7 @@ { "cell_type": "code", "execution_count": 12, - "id": "34866348", + "id": "76837ee3", "metadata": {}, "outputs": [], "source": [ @@ -355,7 +355,7 @@ }, { "cell_type": "markdown", - "id": "4c1f9394", + "id": "28bb0702", "metadata": {}, "source": [ "You can concatenate them with `np.concatenate()`." @@ -364,7 +364,7 @@ { "cell_type": "code", "execution_count": 13, - "id": "a8e8a5e9", + "id": "0f172ac3", "metadata": {}, "outputs": [ { @@ -384,7 +384,7 @@ }, { "cell_type": "markdown", - "id": "5055c367", + "id": "ad8a9627", "metadata": {}, "source": [ "Or, if you start with these arrays:" @@ -393,7 +393,7 @@ { "cell_type": "code", "execution_count": 14, - "id": "23100739", + "id": "b3d5e201", "metadata": {}, "outputs": [], "source": [ @@ -403,7 +403,7 @@ }, { "cell_type": "markdown", - "id": "5350869b", + "id": "38230d50", "metadata": {}, "source": [ "You can concatenate them with:" @@ -412,7 +412,7 @@ { "cell_type": "code", "execution_count": 15, - "id": "d4ed74b9", + "id": "dcc748c4", "metadata": {}, "outputs": [ { @@ -434,7 +434,7 @@ }, { "cell_type": "markdown", - "id": "30cd8b26", + "id": "b9aed6b6", "metadata": {}, "source": [ "In order to remove elements from an array, it’s simple to use indexing to select the elements that you want to keep.\n", @@ -450,7 +450,7 @@ { "cell_type": "code", "execution_count": 16, - "id": "f8986fa7", + "id": "930d5c5a", "metadata": {}, "outputs": [ { @@ -475,7 +475,7 @@ { "cell_type": "code", "execution_count": 17, - "id": "967a1f1f", + "id": "6de83562", "metadata": {}, "outputs": [ { @@ -495,7 +495,7 @@ }, { "cell_type": "markdown", - "id": "44c736bf", + "id": "910fa2fa", "metadata": {}, "source": [ "- ndarray.shape\n", @@ -505,7 +505,7 @@ { "cell_type": "code", "execution_count": 18, - "id": "a9ccebf2", + "id": "4df0897a", "metadata": {}, "outputs": [ { @@ -525,7 +525,7 @@ }, { "cell_type": "markdown", - "id": "a3993a9b", + "id": "a8b7089e", "metadata": {}, "source": [ "- ndarray.size\n", @@ -535,7 +535,7 @@ { "cell_type": "code", "execution_count": 19, - "id": "593dd768", + "id": "4b82bdeb", "metadata": {}, "outputs": [ { @@ -555,7 +555,7 @@ }, { "cell_type": "markdown", - "id": "75dea4f9", + "id": "c46827ca", "metadata": {}, "source": [ "- ndarray.dtype\n", @@ -565,7 +565,7 @@ { "cell_type": "code", "execution_count": 20, - "id": "2db2c6d8", + "id": "1a4fdec5", "metadata": {}, "outputs": [ { @@ -586,7 +586,7 @@ { "cell_type": "code", "execution_count": 21, - "id": "4fee3bd3", + "id": "46cb5a92", "metadata": {}, "outputs": [ { @@ -606,7 +606,7 @@ }, { "cell_type": "markdown", - "id": "a669a2a9", + "id": "63c6eebf", "metadata": {}, "source": [ "- ndarray.itemsize\n", @@ -616,7 +616,7 @@ { "cell_type": "code", "execution_count": 22, - "id": "c09e93a8", + "id": "2d8c0e24", "metadata": {}, "outputs": [ { @@ -636,7 +636,7 @@ }, { "cell_type": "markdown", - "id": "3f744a7d", + "id": "6560f96f", "metadata": {}, "source": [ "- ndarray.data\n", @@ -646,13 +646,13 @@ { "cell_type": "code", "execution_count": 23, - "id": "39e7a739", + "id": "88e890a3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, "execution_count": 23, @@ -666,7 +666,7 @@ }, { "cell_type": "markdown", - "id": "9a208b9b", + "id": "c3608ecd", "metadata": {}, "source": [ "### Reshape an array\n", @@ -679,7 +679,7 @@ { "cell_type": "code", "execution_count": 24, - "id": "06c93a54", + "id": "283a3027", "metadata": {}, "outputs": [ { @@ -700,7 +700,7 @@ }, { "cell_type": "markdown", - "id": "1441f194", + "id": "f77a9c2e", "metadata": {}, "source": [ "You can use `reshape()` to reshape your array. For example, you can reshape this array to an array with three rows and two columns:" @@ -709,7 +709,7 @@ { "cell_type": "code", "execution_count": 25, - "id": "d2d989d5", + "id": "27b6a6f4", "metadata": {}, "outputs": [ { @@ -732,7 +732,7 @@ }, { "cell_type": "markdown", - "id": "599a27ca", + "id": "4f9818e1", "metadata": {}, "source": [ "With `np.reshape`, you can specify a few optional parameters:" @@ -741,7 +741,7 @@ { "cell_type": "code", "execution_count": 26, - "id": "68783c20", + "id": "2b0ab3e9", "metadata": {}, "outputs": [ { @@ -761,7 +761,7 @@ }, { "cell_type": "markdown", - "id": "4de39a60", + "id": "ec4b3d99", "metadata": {}, "source": [ "`a` is the array to be reshaped.\n", @@ -782,7 +782,7 @@ { "cell_type": "code", "execution_count": 27, - "id": "cb11349a", + "id": "c83a127f", "metadata": {}, "outputs": [ { @@ -803,7 +803,7 @@ }, { "cell_type": "markdown", - "id": "03264962", + "id": "fb4550e1", "metadata": {}, "source": [ "You can use `np.newaxis` to add a new axis:" @@ -812,7 +812,7 @@ { "cell_type": "code", "execution_count": 28, - "id": "35ce5839", + "id": "343b677a", "metadata": {}, "outputs": [ { @@ -833,7 +833,7 @@ }, { "cell_type": "markdown", - "id": "0fbbe17f", + "id": "0b886e81", "metadata": {}, "source": [ "You can explicitly convert a 1D array with either a row vector or a column vector using `np.newaxis`. For example, you can convert a 1D array to a row vector by inserting an axis along the first dimension:" @@ -842,7 +842,7 @@ { "cell_type": "code", "execution_count": 29, - "id": "5edcdaaa", + "id": "2396425f", "metadata": {}, "outputs": [ { @@ -863,7 +863,7 @@ }, { "cell_type": "markdown", - "id": "c2c89a10", + "id": "e88e5084", "metadata": {}, "source": [ "Or, for a column vector, you can insert an axis along the second dimension:" @@ -872,7 +872,7 @@ { "cell_type": "code", "execution_count": 30, - "id": "e9262cf1", + "id": "f86eaec4", "metadata": {}, "outputs": [ { @@ -893,7 +893,7 @@ }, { "cell_type": "markdown", - "id": "6177dabb", + "id": "c2ceeaa3", "metadata": {}, "source": [ "You can also expand an array by inserting a new axis at a specified position with `np.expand_dims`.\n", @@ -904,7 +904,7 @@ { "cell_type": "code", "execution_count": 31, - "id": "65479436", + "id": "feaaf5f5", "metadata": {}, "outputs": [ { @@ -925,7 +925,7 @@ }, { "cell_type": "markdown", - "id": "62baae17", + "id": "8179a047", "metadata": {}, "source": [ "You can use np.expand_dims to add an axis at index position 1 with:" @@ -934,7 +934,7 @@ { "cell_type": "code", "execution_count": 32, - "id": "0858aa93", + "id": "f2395964", "metadata": {}, "outputs": [ { @@ -955,7 +955,7 @@ }, { "cell_type": "markdown", - "id": "2f4cdaeb", + "id": "e731906e", "metadata": {}, "source": [ "You can add an axis at index position 0 with:" @@ -964,7 +964,7 @@ { "cell_type": "code", "execution_count": 33, - "id": "f635fed2", + "id": "1e831b21", "metadata": {}, "outputs": [ { @@ -985,7 +985,7 @@ }, { "cell_type": "markdown", - "id": "9a52b417", + "id": "32c57fe6", "metadata": {}, "source": [ "### Indexing and slicing\n", @@ -996,7 +996,7 @@ { "cell_type": "code", "execution_count": 34, - "id": "4478a9aa", + "id": "e6828924", "metadata": {}, "outputs": [], "source": [ @@ -1006,7 +1006,7 @@ { "cell_type": "code", "execution_count": 35, - "id": "12aca91c", + "id": "fcf6182e", "metadata": {}, "outputs": [ { @@ -1027,7 +1027,7 @@ { "cell_type": "code", "execution_count": 36, - "id": "ec7c1d6e", + "id": "db06cad3", "metadata": {}, "outputs": [ { @@ -1048,7 +1048,7 @@ { "cell_type": "code", "execution_count": 37, - "id": "b47ac74f", + "id": "77460fae", "metadata": {}, "outputs": [ { @@ -1069,7 +1069,7 @@ { "cell_type": "code", "execution_count": 38, - "id": "b65e8f39", + "id": "50d3d7d5", "metadata": {}, "outputs": [ { @@ -1089,7 +1089,7 @@ }, { "cell_type": "markdown", - "id": "2062f21e", + "id": "390f7286", "metadata": {}, "source": [ "You may want to take a section of your array or specific array elements to use in further analysis or additional operations. To do that, you’ll need to subset, slice, and/or index your arrays.\n", @@ -1102,7 +1102,7 @@ { "cell_type": "code", "execution_count": 39, - "id": "ce39df14", + "id": "bfabe582", "metadata": {}, "outputs": [], "source": [ @@ -1111,7 +1111,7 @@ }, { "cell_type": "markdown", - "id": "4cf627fa", + "id": "98d7b447", "metadata": {}, "source": [ "You can easily print all of the values in the array that are less than 5." @@ -1120,7 +1120,7 @@ { "cell_type": "code", "execution_count": 40, - "id": "7a917f2c", + "id": "7b481bbb", "metadata": {}, "outputs": [ { @@ -1140,7 +1140,7 @@ }, { "cell_type": "markdown", - "id": "c4a80f02", + "id": "a1f20041", "metadata": {}, "source": [ "You can also select, for example, numbers that are equal to or greater than 5, and use that condition to index an array." @@ -1149,7 +1149,7 @@ { "cell_type": "code", "execution_count": 41, - "id": "8be48517", + "id": "abbbef5c", "metadata": {}, "outputs": [ { @@ -1170,7 +1170,7 @@ }, { "cell_type": "markdown", - "id": "5fa1b730", + "id": "5f9efe6e", "metadata": {}, "source": [ "You can select elements that are divisible by 2:" @@ -1179,7 +1179,7 @@ { "cell_type": "code", "execution_count": 42, - "id": "8b3171b7", + "id": "6fcf8c82", "metadata": {}, "outputs": [ { @@ -1200,7 +1200,7 @@ }, { "cell_type": "markdown", - "id": "ef7461fb", + "id": "ac07b8bf", "metadata": {}, "source": [ "Or you can select elements that satisfy two conditions using the `&` and `|` operators:" @@ -1209,7 +1209,7 @@ { "cell_type": "code", "execution_count": 43, - "id": "9eed50a5", + "id": "a6c02448", "metadata": {}, "outputs": [ { @@ -1230,7 +1230,7 @@ }, { "cell_type": "markdown", - "id": "29f86723", + "id": "9aea32e3", "metadata": {}, "source": [ "You can also make use of the logical operators `&` and `|` in order to return boolean values that specify whether or not the values in an array fulfill a certain condition. This can be useful with arrays that contain names or other categorical values." @@ -1239,7 +1239,7 @@ { "cell_type": "code", "execution_count": 44, - "id": "6003d0d8", + "id": "52e1a2a9", "metadata": {}, "outputs": [ { @@ -1262,7 +1262,7 @@ }, { "cell_type": "markdown", - "id": "2bb6f36d", + "id": "6196ee04", "metadata": {}, "source": [ "You can also use `np.nonzero()` to select elements or indices from an array.\n", @@ -1273,7 +1273,7 @@ { "cell_type": "code", "execution_count": 45, - "id": "8b800a53", + "id": "84de3fc8", "metadata": {}, "outputs": [], "source": [ @@ -1282,7 +1282,7 @@ }, { "cell_type": "markdown", - "id": "5a961d69", + "id": "62b27c24", "metadata": {}, "source": [ "You can use `np.nonzero()` to print the indices of elements that are, for example, less than 5:" @@ -1291,7 +1291,7 @@ { "cell_type": "code", "execution_count": 46, - "id": "3d62685b", + "id": "bf9b79b9", "metadata": {}, "outputs": [ { @@ -1312,7 +1312,7 @@ }, { "cell_type": "markdown", - "id": "35ca8cba", + "id": "be13baec", "metadata": {}, "source": [ "In this example, a tuple of arrays was returned: one for each dimension. The first array represents the row indices where these values are found, and the second array represents the column indices where the values are found.\n", @@ -1323,7 +1323,7 @@ { "cell_type": "code", "execution_count": 47, - "id": "8f21e63f", + "id": "6e50ff11", "metadata": {}, "outputs": [ { @@ -1345,7 +1345,7 @@ }, { "cell_type": "markdown", - "id": "a799850f", + "id": "2eecc043", "metadata": {}, "source": [ "You can also use `np.nonzero()` to print the elements in an array that are less than 5 with:" @@ -1354,7 +1354,7 @@ { "cell_type": "code", "execution_count": 48, - "id": "49469b0c", + "id": "e6439bbf", "metadata": {}, "outputs": [ { @@ -1374,7 +1374,7 @@ }, { "cell_type": "markdown", - "id": "b3380d45", + "id": "85a29814", "metadata": {}, "source": [ "If the element you’re looking for doesn’t exist in the array, then the returned array of indices will be empty. For example:" @@ -1383,7 +1383,7 @@ { "cell_type": "code", "execution_count": 49, - "id": "b4285507", + "id": "454088ea", "metadata": {}, "outputs": [ { @@ -1404,7 +1404,7 @@ }, { "cell_type": "markdown", - "id": "d53b5fbc", + "id": "8be2d548", "metadata": {}, "source": [ "### Create an array from existing data\n", @@ -1417,7 +1417,7 @@ { "cell_type": "code", "execution_count": 50, - "id": "54706621", + "id": "62890d3d", "metadata": {}, "outputs": [], "source": [ @@ -1426,7 +1426,7 @@ }, { "cell_type": "markdown", - "id": "c766ba58", + "id": "e7bdf8cb", "metadata": {}, "source": [ "You can create a new array from a section of your array any time by specifying where you want to slice your array." @@ -1435,7 +1435,7 @@ { "cell_type": "code", "execution_count": 51, - "id": "02e1325d", + "id": "cf1bb50c", "metadata": {}, "outputs": [ { @@ -1456,7 +1456,7 @@ }, { "cell_type": "markdown", - "id": "049a3c10", + "id": "b4a69e71", "metadata": {}, "source": [ "Here, you grabbed a section of your array from index position 3 through index position 8.\n", @@ -1467,7 +1467,7 @@ { "cell_type": "code", "execution_count": 52, - "id": "799f7457", + "id": "e8d3491c", "metadata": {}, "outputs": [], "source": [ @@ -1479,7 +1479,7 @@ }, { "cell_type": "markdown", - "id": "9bfa917c", + "id": "a1fd82bb", "metadata": {}, "source": [ "You can stack them vertically with `vstack`:" @@ -1488,7 +1488,7 @@ { "cell_type": "code", "execution_count": 53, - "id": "4a0130d4", + "id": "2b133e0b", "metadata": {}, "outputs": [ { @@ -1511,7 +1511,7 @@ }, { "cell_type": "markdown", - "id": "7e52a789", + "id": "cb12b0c2", "metadata": {}, "source": [ "Or stack them horizontally with hstack:" @@ -1520,7 +1520,7 @@ { "cell_type": "code", "execution_count": 54, - "id": "1e4fedae", + "id": "bce35ecd", "metadata": {}, "outputs": [ { @@ -1541,7 +1541,7 @@ }, { "cell_type": "markdown", - "id": "9a5d31fc", + "id": "e28a6f04", "metadata": {}, "source": [ "You can split an array into several smaller arrays using `hsplit`. You can specify either the number of equally shaped arrays to return or the columns after which the division should occur.\n", @@ -1552,7 +1552,7 @@ { "cell_type": "code", "execution_count": 55, - "id": "c5799472", + "id": "f99bd667", "metadata": {}, "outputs": [ { @@ -1574,7 +1574,7 @@ }, { "cell_type": "markdown", - "id": "9b1bdf6f", + "id": "cbc08091", "metadata": {}, "source": [ "If you wanted to split this array into three equally shaped arrays, you would run:" @@ -1583,7 +1583,7 @@ { "cell_type": "code", "execution_count": 56, - "id": "35d2411e", + "id": "14c2c436", "metadata": {}, "outputs": [ { @@ -1608,7 +1608,7 @@ }, { "cell_type": "markdown", - "id": "7d09ed68", + "id": "35b81ae5", "metadata": {}, "source": [ "If you wanted to split your array after the third and fourth column, you’d run:" @@ -1617,7 +1617,7 @@ { "cell_type": "code", "execution_count": 57, - "id": "d1d99f79", + "id": "dcaf2edb", "metadata": {}, "outputs": [ { @@ -1642,7 +1642,7 @@ }, { "cell_type": "markdown", - "id": "54bd653b", + "id": "c81861d9", "metadata": {}, "source": [ "You can use the `view` method to create a new array object that looks at the same data as the original array (a shallow copy).\n", @@ -1655,7 +1655,7 @@ { "cell_type": "code", "execution_count": 58, - "id": "13933ea2", + "id": "234f0412", "metadata": {}, "outputs": [], "source": [ @@ -1664,7 +1664,7 @@ }, { "cell_type": "markdown", - "id": "8e3c6c29", + "id": "af503dcd", "metadata": {}, "source": [ "Now we create an array `b1` by slicing `a` and modify the first element of `b1`. This will modify the corresponding element in `a` as well!" @@ -1673,7 +1673,7 @@ { "cell_type": "code", "execution_count": 59, - "id": "e4932af5", + "id": "845c5d61", "metadata": {}, "outputs": [ { @@ -1695,7 +1695,7 @@ { "cell_type": "code", "execution_count": 60, - "id": "6449ba38", + "id": "106bbd4b", "metadata": {}, "outputs": [ { @@ -1717,7 +1717,7 @@ { "cell_type": "code", "execution_count": 61, - "id": "02c6daa1", + "id": "a3cea45b", "metadata": {}, "outputs": [ { @@ -1739,7 +1739,7 @@ }, { "cell_type": "markdown", - "id": "915560de", + "id": "09b0efa2", "metadata": {}, "source": [ "Using the `copy` method will make a complete copy of the array and its data (a deep copy). To use this on your array, you could run:" @@ -1748,7 +1748,7 @@ { "cell_type": "code", "execution_count": 62, - "id": "ee8caaec", + "id": "e97bbc37", "metadata": {}, "outputs": [], "source": [ @@ -1757,7 +1757,7 @@ }, { "cell_type": "markdown", - "id": "c8bed026", + "id": "840ff748", "metadata": {}, "source": [ "## Array operations\n", @@ -1770,7 +1770,7 @@ { "cell_type": "code", "execution_count": 63, - "id": "4a349415", + "id": "d34c3785", "metadata": {}, "outputs": [], "source": [ @@ -1780,7 +1780,7 @@ }, { "cell_type": "markdown", - "id": "7fb082fa", + "id": "354b812c", "metadata": {}, "source": [ "You can add the arrays together with the plus sign." @@ -1789,7 +1789,7 @@ { "cell_type": "code", "execution_count": 64, - "id": "0d0708be", + "id": "044a9d38", "metadata": {}, "outputs": [ { @@ -1809,7 +1809,7 @@ }, { "cell_type": "markdown", - "id": "8bcd971c", + "id": "ca6b8eee", "metadata": {}, "source": [ "You can, of course, do more than just addition!" @@ -1818,7 +1818,7 @@ { "cell_type": "code", "execution_count": 65, - "id": "10d49931", + "id": "02080dd2", "metadata": {}, "outputs": [ { @@ -1839,7 +1839,7 @@ }, { "cell_type": "markdown", - "id": "f9924a5c", + "id": "06df329f", "metadata": {}, "source": [ "Basic operations are simple with NumPy. If you want to find the sum of the elements in an array, you’d use `sum()`. This works for 1D arrays, 2D arrays, and arrays in higher dimensions." @@ -1848,7 +1848,7 @@ { "cell_type": "code", "execution_count": 66, - "id": "bb0fcf79", + "id": "d5942646", "metadata": {}, "outputs": [ { @@ -1869,7 +1869,7 @@ }, { "cell_type": "markdown", - "id": "202fc319", + "id": "de4ae5f1", "metadata": {}, "source": [ "To add the rows or the columns in a 2D array, you would specify the axis.\n", @@ -1880,7 +1880,7 @@ { "cell_type": "code", "execution_count": 67, - "id": "7c587b0e", + "id": "797ef075", "metadata": {}, "outputs": [], "source": [ @@ -1889,7 +1889,7 @@ }, { "cell_type": "markdown", - "id": "0db5b5e7", + "id": "d6326b81", "metadata": {}, "source": [ "You can sum over the axis of rows with:" @@ -1898,7 +1898,7 @@ { "cell_type": "code", "execution_count": 68, - "id": "182a80b1", + "id": "879ed4b6", "metadata": {}, "outputs": [ { @@ -1918,7 +1918,7 @@ }, { "cell_type": "markdown", - "id": "758c0601", + "id": "1d1d6798", "metadata": {}, "source": [ "You can sum over the axis of columns with:" @@ -1927,7 +1927,7 @@ { "cell_type": "code", "execution_count": 69, - "id": "93a8295a", + "id": "89742bc3", "metadata": {}, "outputs": [ { @@ -1947,7 +1947,7 @@ }, { "cell_type": "markdown", - "id": "043250a0", + "id": "e05aea65", "metadata": {}, "source": [ "### Universal functions(ufunc)\n", @@ -2038,7 +2038,7 @@ { "cell_type": "code", "execution_count": 70, - "id": "9a215dfc", + "id": "2e7a2827", "metadata": {}, "outputs": [ { @@ -2060,7 +2060,7 @@ }, { "cell_type": "markdown", - "id": "d64eff6c", + "id": "e14d53f4", "metadata": {}, "source": [ "NumPy’s broadcasting rule relaxes this constraint when the arrays’ shapes meet certain constraints. The simplest broadcasting example occurs when an array and a scalar value are combined in an operation:" @@ -2069,7 +2069,7 @@ { "cell_type": "code", "execution_count": 71, - "id": "8e2e9d52", + "id": "3034ee65", "metadata": {}, "outputs": [ { @@ -2091,7 +2091,7 @@ }, { "cell_type": "markdown", - "id": "d705672b", + "id": "b32494fc", "metadata": {}, "source": [ "The result is equivalent to the previous example where `b` was an array. NumPy is smart enough to use the original scalar value without actually making copies so that broadcasting operations are as memory and computationally efficient as possible.\n", @@ -2133,7 +2133,7 @@ { "cell_type": "code", "execution_count": 72, - "id": "46c0d2bf", + "id": "dfec7dfa", "metadata": {}, "outputs": [ { @@ -2154,7 +2154,7 @@ { "cell_type": "code", "execution_count": 73, - "id": "e709baf5", + "id": "b109968d", "metadata": {}, "outputs": [ { @@ -2175,7 +2175,7 @@ { "cell_type": "code", "execution_count": 74, - "id": "3c00aa67", + "id": "14573901", "metadata": {}, "outputs": [ { @@ -2195,7 +2195,7 @@ }, { "cell_type": "markdown", - "id": "b44670c3", + "id": "827494ec", "metadata": {}, "source": [ "Let’s start with this array, called “a”." @@ -2204,7 +2204,7 @@ { "cell_type": "code", "execution_count": 75, - "id": "4449fcff", + "id": "8fbcc6fd", "metadata": {}, "outputs": [], "source": [ @@ -2215,7 +2215,7 @@ }, { "cell_type": "markdown", - "id": "ce3fcc42", + "id": "9bb857c3", "metadata": {}, "source": [ "It’s very common to want to aggregate along a row or column. By default, every NumPy aggregation function will return the aggregate of the entire array. To find the sum or the minimum of the elements in your array, run:" @@ -2224,7 +2224,7 @@ { "cell_type": "code", "execution_count": 76, - "id": "45350736", + "id": "1365f7c7", "metadata": {}, "outputs": [ { @@ -2244,7 +2244,7 @@ }, { "cell_type": "markdown", - "id": "46c11980", + "id": "7d979114", "metadata": {}, "source": [ "Or:" @@ -2253,7 +2253,7 @@ { "cell_type": "code", "execution_count": 77, - "id": "ea5ab3e7", + "id": "d01f3f34", "metadata": {}, "outputs": [ { @@ -2273,7 +2273,7 @@ }, { "cell_type": "markdown", - "id": "15bfcfe8", + "id": "6b75981d", "metadata": {}, "source": [ "You can specify on which axis you want the aggregation function to be computed. For example, you can find the minimum value within each column by specifying `axis=0`." @@ -2282,7 +2282,7 @@ { "cell_type": "code", "execution_count": 78, - "id": "8ce375bd", + "id": "b877a6d2", "metadata": {}, "outputs": [ { @@ -2302,7 +2302,7 @@ }, { "cell_type": "markdown", - "id": "1762c1e5", + "id": "0f014088", "metadata": {}, "source": [ "The four values listed above correspond to the number of columns in your array. With a four-column array, you will get four values as your result.\n", @@ -2325,7 +2325,7 @@ { "cell_type": "code", "execution_count": 79, - "id": "58e8f5c8", + "id": "11a0d9b8", "metadata": {}, "outputs": [], "source": [ @@ -2335,7 +2335,7 @@ { "cell_type": "code", "execution_count": 80, - "id": "f57ea41e", + "id": "e5904a16", "metadata": {}, "outputs": [ { @@ -2356,7 +2356,7 @@ { "cell_type": "code", "execution_count": 81, - "id": "f6618b66", + "id": "b1f20faa", "metadata": {}, "outputs": [ { @@ -2376,7 +2376,7 @@ }, { "cell_type": "markdown", - "id": "d9e8337f", + "id": "78347e54", "metadata": {}, "source": [ "It is not necessary to separate each dimension’s index into its own set of square brackets." @@ -2385,7 +2385,7 @@ { "cell_type": "code", "execution_count": 82, - "id": "8a2af3b4", + "id": "38396974", "metadata": {}, "outputs": [], "source": [ @@ -2395,7 +2395,7 @@ { "cell_type": "code", "execution_count": 83, - "id": "bbcc35b0", + "id": "14246c83", "metadata": {}, "outputs": [ { @@ -2416,7 +2416,7 @@ { "cell_type": "code", "execution_count": 84, - "id": "4cefdbb1", + "id": "d964c396", "metadata": {}, "outputs": [ { @@ -2436,7 +2436,7 @@ }, { "cell_type": "markdown", - "id": "d4116765", + "id": "f4db7183", "metadata": {}, "source": [ "Note that If one indexes a multidimensional array with fewer indices than dimensions, one gets a subdimensional array. For example:" @@ -2445,7 +2445,7 @@ { "cell_type": "code", "execution_count": 85, - "id": "e98b454b", + "id": "b3063d7f", "metadata": {}, "outputs": [ { @@ -2465,7 +2465,7 @@ }, { "cell_type": "markdown", - "id": "5a304a07", + "id": "302f6ed0", "metadata": {}, "source": [ "That is, each index specified selects the array corresponding to the rest of the dimensions selected. In the above example, choosing 0 means that the remaining dimension of length 5 is being left unspecified, and that what is returned is an array of that dimensionality and size. It must be noted that the returned array is a view, i.e., it is not a copy of the original, but points to the same values in memory as does the original array. In this case, the 1-D array at the first position (0) is returned. So using a single index on the returned array, results in a single element being returned. That is:" @@ -2474,7 +2474,7 @@ { "cell_type": "code", "execution_count": 86, - "id": "87c536b5", + "id": "b61a9fd7", "metadata": {}, "outputs": [ { @@ -2494,7 +2494,7 @@ }, { "cell_type": "markdown", - "id": "761ba225", + "id": "35a67fd4", "metadata": {}, "source": [ "So note that `x[0, 2] == x[0][2]` though the second case is more inefficient as a new temporary array is created after the first index that is subsequently indexed by 2.\n", @@ -2521,7 +2521,7 @@ { "cell_type": "code", "execution_count": 87, - "id": "9d22d64a", + "id": "5d86e072", "metadata": {}, "outputs": [ { @@ -2542,7 +2542,7 @@ }, { "cell_type": "markdown", - "id": "8142b7d4", + "id": "c642e2bd", "metadata": {}, "source": [ "- Negative *i* and *j* are interpreted as *n + i* and *n + j* where *n* is the number of elements in the corresponding dimension. Negative *k* makes stepping go towards smaller indices. From the above example:" @@ -2551,7 +2551,7 @@ { "cell_type": "code", "execution_count": 88, - "id": "a6e27651", + "id": "c98b0c5a", "metadata": {}, "outputs": [ { @@ -2572,7 +2572,7 @@ { "cell_type": "code", "execution_count": 89, - "id": "d13f6700", + "id": "3a57ee72", "metadata": {}, "outputs": [ { @@ -2592,7 +2592,7 @@ }, { "cell_type": "markdown", - "id": "095b0390", + "id": "fbf154df", "metadata": {}, "source": [ "- Assume *n* is the number of elements in the dimension being sliced. Then, if *i* is not given it defaults to 0 for *k > 0* and *n - 1* for *k < 0*. If *j* is not given it defaults to *n* for *k > 0* and *-n-1* for *k < 0*. If *k* is not given it defaults to 1. Note that `::` is the same as : and means select all indices along this axis. From the above example:" @@ -2601,7 +2601,7 @@ { "cell_type": "code", "execution_count": 90, - "id": "2cea56f9", + "id": "54fa2284", "metadata": {}, "outputs": [ { @@ -2621,7 +2621,7 @@ }, { "cell_type": "markdown", - "id": "3b827af9", + "id": "8cacdc50", "metadata": {}, "source": [ "- If the number of objects in the selection tuple is less than N, then `:` is assumed for any subsequent dimensions. For example:" @@ -2630,7 +2630,7 @@ { "cell_type": "code", "execution_count": 91, - "id": "20bb9974", + "id": "a6a38346", "metadata": {}, "outputs": [ { @@ -2652,7 +2652,7 @@ { "cell_type": "code", "execution_count": 92, - "id": "ffe7e2b1", + "id": "45fd34c7", "metadata": {}, "outputs": [ { @@ -2674,7 +2674,7 @@ }, { "cell_type": "markdown", - "id": "9ef2c35f", + "id": "bd80540c", "metadata": {}, "source": [ "- An integer, *i*, returns the same values as `i:i+1` **except** the dimensionality of the returned object is reduced by 1. In particular, a selection tuple with the *p*-th element an integer (and all other entries *:*) returns the corresponding sub-array with dimension *N - 1*. If *N = 1* then the returned object is an array scalar.\n", @@ -2699,7 +2699,7 @@ { "cell_type": "code", "execution_count": 93, - "id": "ceec2fb4", + "id": "cf487e2a", "metadata": {}, "outputs": [ { @@ -2720,7 +2720,7 @@ }, { "cell_type": "markdown", - "id": "1aff7de2", + "id": "cea60560", "metadata": {}, "source": [ "This is equivalent to:" @@ -2729,7 +2729,7 @@ { "cell_type": "code", "execution_count": 94, - "id": "7b49a3cd", + "id": "256b0b53", "metadata": {}, "outputs": [ { @@ -2750,7 +2750,7 @@ }, { "cell_type": "markdown", - "id": "7ded2831", + "id": "f0852ec8", "metadata": {}, "source": [ "Each `newaxis` object in the selection tuple serves to expand the dimensions of the resulting selection by one unit-length dimension. The added dimension is the position of the `newaxis` object in the selection tuple. `newaxis` is an alias for `None`, and `None` can be used in place of this with the same result. From the above example:" @@ -2759,7 +2759,7 @@ { "cell_type": "code", "execution_count": 95, - "id": "74bbbb53", + "id": "f3949020", "metadata": {}, "outputs": [ { @@ -2780,7 +2780,7 @@ { "cell_type": "code", "execution_count": 96, - "id": "7b394ddd", + "id": "9c51768b", "metadata": {}, "outputs": [ { @@ -2800,7 +2800,7 @@ }, { "cell_type": "markdown", - "id": "778232cd", + "id": "d342e127", "metadata": {}, "source": [ "This can be handy to combine two arrays in a way that otherwise would require explicit reshaping operations. For example:" @@ -2809,7 +2809,7 @@ { "cell_type": "code", "execution_count": 97, - "id": "de655a5c", + "id": "adbe9075", "metadata": {}, "outputs": [ { @@ -2834,7 +2834,7 @@ }, { "cell_type": "markdown", - "id": "e4704ed9", + "id": "b17566e0", "metadata": {}, "source": [ "### Advanced indexing\n", @@ -2857,7 +2857,7 @@ { "cell_type": "code", "execution_count": 98, - "id": "caeb904c", + "id": "02932a10", "metadata": {}, "outputs": [], "source": [ @@ -2867,7 +2867,7 @@ { "cell_type": "code", "execution_count": 99, - "id": "a6266860", + "id": "7f8fdde1", "metadata": {}, "outputs": [ { @@ -2888,7 +2888,7 @@ { "cell_type": "code", "execution_count": 100, - "id": "b1b58910", + "id": "a8a7ea68", "metadata": {}, "outputs": [ { @@ -2909,7 +2909,7 @@ { "cell_type": "code", "execution_count": 101, - "id": "a34dda1e", + "id": "5ccb1438", "metadata": {}, "outputs": [ { @@ -2929,7 +2929,7 @@ }, { "cell_type": "markdown", - "id": "80cf5e75", + "id": "96d8e32b", "metadata": {}, "source": [ "If the index values are out of bounds then an `IndexError` is thrown:" @@ -2938,7 +2938,7 @@ { "cell_type": "code", "execution_count": 102, - "id": "cd710942", + "id": "43a4fb4a", "metadata": {}, "outputs": [], "source": [ @@ -2948,7 +2948,7 @@ { "cell_type": "code", "execution_count": 103, - "id": "d05ea078", + "id": "f065ee6a", "metadata": {}, "outputs": [ { @@ -2969,7 +2969,7 @@ }, { "cell_type": "markdown", - "id": "42f0d065", + "id": "e7c13101", "metadata": {}, "source": [ "```py\n", @@ -2999,7 +2999,7 @@ { "cell_type": "code", "execution_count": 104, - "id": "5150ac27", + "id": "063101bc", "metadata": {}, "outputs": [], "source": [ @@ -3009,7 +3009,7 @@ { "cell_type": "code", "execution_count": 105, - "id": "769e4f9b", + "id": "e4a0954b", "metadata": {}, "outputs": [ { @@ -3034,7 +3034,7 @@ { "cell_type": "code", "execution_count": 106, - "id": "346ea0c7", + "id": "f5399375", "metadata": {}, "outputs": [ { @@ -3054,7 +3054,7 @@ }, { "cell_type": "markdown", - "id": "ce83ecd8", + "id": "54a9e869", "metadata": {}, "source": [ "In this case, if the index arrays have a matching shape, and there is an index array for each dimension of the array being indexed, the resultant array has the same shape as the index arrays, and the values correspond to the index set for each position in the index arrays. In this example, the first index value is 0 for both index arrays, and thus the first value of the resultant array is `y[0, 0]`. The next value is `y[2, 1]`, and the last is `y[4, 2]`.\n", @@ -3077,7 +3077,7 @@ { "cell_type": "code", "execution_count": 107, - "id": "dec489d5", + "id": "b5f16305", "metadata": {}, "outputs": [ { @@ -3097,7 +3097,7 @@ }, { "cell_type": "markdown", - "id": "16fce1af", + "id": "31c71ff4", "metadata": {}, "source": [ "Jumping to the next level of complexity, it is possible to only partially index an array with index arrays. It takes a bit of thought to understand what happens in such cases. For example if we just use one index array with y:" @@ -3106,7 +3106,7 @@ { "cell_type": "code", "execution_count": 108, - "id": "e5b6d2ba", + "id": "c844ded4", "metadata": {}, "outputs": [ { @@ -3128,7 +3128,7 @@ }, { "cell_type": "markdown", - "id": "fdf6289c", + "id": "ac086385", "metadata": {}, "source": [ "It results in the construction of a new array where each value of the index array selects one row from the array being indexed and the resultant array has the resulting shape (number of index elements, size of row).\n", @@ -3143,7 +3143,7 @@ { "cell_type": "code", "execution_count": 109, - "id": "a1dc3d6d", + "id": "0570bd1c", "metadata": {}, "outputs": [ { @@ -3164,7 +3164,7 @@ }, { "cell_type": "markdown", - "id": "c20e5a41", + "id": "a3dcf6fe", "metadata": {}, "source": [ "To achieve a behaviour similar to the basic slicing above, broadcasting can be used. The function `ix_` can help with this broadcasting. This is best understood with an example.\n", @@ -3177,7 +3177,7 @@ { "cell_type": "code", "execution_count": 110, - "id": "268d1657", + "id": "9bafc89a", "metadata": {}, "outputs": [ { @@ -3206,7 +3206,7 @@ }, { "cell_type": "markdown", - "id": "67e00413", + "id": "e2c55b65", "metadata": {}, "source": [ "However, since the indexing arrays above just repeat themselves, broadcasting can be used (compare operations such as `rows[:, np.newaxis] + columns`) to simplify this:" @@ -3215,7 +3215,7 @@ { "cell_type": "code", "execution_count": 111, - "id": "a6fe9f30", + "id": "7c316750", "metadata": {}, "outputs": [], "source": [ @@ -3226,7 +3226,7 @@ { "cell_type": "code", "execution_count": 112, - "id": "ef347053", + "id": "15afb73a", "metadata": {}, "outputs": [ { @@ -3248,7 +3248,7 @@ { "cell_type": "code", "execution_count": 113, - "id": "28dbb17f", + "id": "30c1524d", "metadata": {}, "outputs": [ { @@ -3269,7 +3269,7 @@ }, { "cell_type": "markdown", - "id": "79640426", + "id": "90a1e37e", "metadata": {}, "source": [ "This broadcasting can also be achieved using the function `ix_`:" @@ -3278,7 +3278,7 @@ { "cell_type": "code", "execution_count": 114, - "id": "f209910e", + "id": "c1cc2872", "metadata": {}, "outputs": [ { @@ -3299,7 +3299,7 @@ }, { "cell_type": "markdown", - "id": "78141d63", + "id": "4e044e8a", "metadata": {}, "source": [ "Note that without the `np.ix_` call, only the diagonal elements would be selected:" @@ -3308,7 +3308,7 @@ { "cell_type": "code", "execution_count": 115, - "id": "160f5d4f", + "id": "f13887ba", "metadata": {}, "outputs": [ { @@ -3328,7 +3328,7 @@ }, { "cell_type": "markdown", - "id": "caed449a", + "id": "cb1e8cf2", "metadata": {}, "source": [ "This difference is the most important thing to remember about indexing with multiple advanced indices.\n", @@ -3349,7 +3349,7 @@ { "cell_type": "code", "execution_count": 116, - "id": "def11a0f", + "id": "05271311", "metadata": {}, "outputs": [ { @@ -3370,7 +3370,7 @@ }, { "cell_type": "markdown", - "id": "4c24f5b3", + "id": "ec5b9a35", "metadata": {}, "source": [ "Or wish to add a constant to all negative elements:" @@ -3379,7 +3379,7 @@ { "cell_type": "code", "execution_count": 117, - "id": "f85d658f", + "id": "291fff1d", "metadata": {}, "outputs": [ { @@ -3401,7 +3401,7 @@ }, { "cell_type": "markdown", - "id": "7b33c4f0", + "id": "034c1975", "metadata": {}, "source": [ "In general if an index includes a Boolean array, the result will be identical to inserting `obj.nonzero()` into the same position and using the integer array indexing mechanism described above. `x[ind_1, boolean_array, ind_2]` is equivalent to `x[(ind_1,) + boolean_array.nonzero() + (ind_2,)]`.\n", @@ -3414,7 +3414,7 @@ { "cell_type": "code", "execution_count": 118, - "id": "53eade9b", + "id": "c58aa8b3", "metadata": {}, "outputs": [], "source": [ @@ -3425,7 +3425,7 @@ { "cell_type": "code", "execution_count": 119, - "id": "ece1b5d1", + "id": "21849360", "metadata": {}, "outputs": [ { @@ -3446,7 +3446,7 @@ { "cell_type": "code", "execution_count": 120, - "id": "c52c46bb", + "id": "e6924d97", "metadata": {}, "outputs": [ { @@ -3467,7 +3467,7 @@ }, { "cell_type": "markdown", - "id": "a3118f6f", + "id": "2cbb48f6", "metadata": {}, "source": [ "Here the 4th and 5th rows are selected from the indexed array and combined to make a 2-D array.\n", @@ -3480,7 +3480,7 @@ { "cell_type": "code", "execution_count": 121, - "id": "7708360b", + "id": "612560aa", "metadata": {}, "outputs": [ { @@ -3503,7 +3503,7 @@ }, { "cell_type": "markdown", - "id": "7087ef20", + "id": "4c8ed0c7", "metadata": {}, "source": [ "Combining multiple Boolean indexing arrays or a Boolean with an integer indexing array can best be understood with the `obj.nonzero()` analogy. The function `ix_` also supports boolean arrays and will work without any surprises.\n", @@ -3516,7 +3516,7 @@ { "cell_type": "code", "execution_count": 122, - "id": "41965626", + "id": "c8309bd2", "metadata": {}, "outputs": [], "source": [ @@ -3530,7 +3530,7 @@ { "cell_type": "code", "execution_count": 123, - "id": "baf4625d", + "id": "6f96cb8a", "metadata": {}, "outputs": [ { @@ -3551,7 +3551,7 @@ { "cell_type": "code", "execution_count": 124, - "id": "43d558dc", + "id": "11741b5c", "metadata": {}, "outputs": [], "source": [ @@ -3561,7 +3561,7 @@ { "cell_type": "code", "execution_count": 125, - "id": "9d2a6bab", + "id": "fd39a729", "metadata": {}, "outputs": [ { @@ -3582,7 +3582,7 @@ }, { "cell_type": "markdown", - "id": "86f9ff85", + "id": "7ddc6b28", "metadata": {}, "source": [ "Without the n`p.ix_` call, only the diagonal elements would be selected.\n", @@ -3593,7 +3593,7 @@ { "cell_type": "code", "execution_count": 126, - "id": "5fd35947", + "id": "7ccf9464", "metadata": {}, "outputs": [ { @@ -3615,7 +3615,7 @@ }, { "cell_type": "markdown", - "id": "99e52279", + "id": "564a7af0", "metadata": {}, "source": [ "##### Example 3\n", @@ -3626,7 +3626,7 @@ { "cell_type": "code", "execution_count": 127, - "id": "7f7a1f6b", + "id": "dce8c929", "metadata": {}, "outputs": [ { @@ -3654,7 +3654,7 @@ { "cell_type": "code", "execution_count": 128, - "id": "9cd72543", + "id": "bcd7a12b", "metadata": {}, "outputs": [ { @@ -3678,7 +3678,7 @@ }, { "cell_type": "markdown", - "id": "ad082716", + "id": "a7da394e", "metadata": {}, "source": [ "#### Combining advanced and basic indexing\n", @@ -3691,7 +3691,7 @@ { "cell_type": "code", "execution_count": 129, - "id": "721423b9", + "id": "dc2df71d", "metadata": {}, "outputs": [ { @@ -3714,7 +3714,7 @@ }, { "cell_type": "markdown", - "id": "7df99050", + "id": "28f3afe5", "metadata": {}, "source": [ "In effect, the slice and index array operation are independent. The slice operation extracts columns with index 1 and 2, (i.e. the 2nd and 3rd columns), followed by the index array operation which extracts rows with index 0, 2 and 4 (i.e the first, third and fifth rows). This is equivalent to:" @@ -3723,7 +3723,7 @@ { "cell_type": "code", "execution_count": 130, - "id": "f678ffe3", + "id": "d61f25a8", "metadata": {}, "outputs": [ { @@ -3745,7 +3745,7 @@ }, { "cell_type": "markdown", - "id": "7aad416f", + "id": "907b0b9d", "metadata": {}, "source": [ "A single advanced index can, for example, replace a slice and the result array will be the same. However, it is a copy and may have a different memory layout. A slice is preferable when it is possible. For example:" @@ -3754,7 +3754,7 @@ { "cell_type": "code", "execution_count": 131, - "id": "d25f4b37", + "id": "9a400503", "metadata": {}, "outputs": [], "source": [ @@ -3767,7 +3767,7 @@ { "cell_type": "code", "execution_count": 132, - "id": "3bffaf98", + "id": "95b3f42f", "metadata": {}, "outputs": [ { @@ -3788,7 +3788,7 @@ { "cell_type": "code", "execution_count": 133, - "id": "c719ffa9", + "id": "0dbd6221", "metadata": {}, "outputs": [ { @@ -3808,7 +3808,7 @@ }, { "cell_type": "markdown", - "id": "23a538a8", + "id": "718eb852", "metadata": {}, "source": [ "The easiest way to understand a combination of multiple advanced indices may be to think in terms of the resulting shape. There are two parts to the indexing operation, the subspace defined by the basic indexing (excluding integers) and the subspace from the advanced indexing part. Two cases of index combination need to be distinguished:\n", @@ -3834,7 +3834,7 @@ { "cell_type": "code", "execution_count": 134, - "id": "d653d61c", + "id": "b840bdb4", "metadata": {}, "outputs": [], "source": [ @@ -3845,7 +3845,7 @@ { "cell_type": "code", "execution_count": 135, - "id": "8428a5bc", + "id": "4031f15a", "metadata": {}, "outputs": [ { @@ -3870,7 +3870,7 @@ { "cell_type": "code", "execution_count": 136, - "id": "0556f002", + "id": "e16ef04d", "metadata": {}, "outputs": [ { @@ -3891,7 +3891,7 @@ }, { "cell_type": "markdown", - "id": "6a819f14", + "id": "022fb178", "metadata": {}, "source": [ "### Field access\n", @@ -3908,7 +3908,7 @@ { "cell_type": "code", "execution_count": 137, - "id": "8afb1ed2", + "id": "dc4dfd32", "metadata": {}, "outputs": [], "source": [ @@ -3918,7 +3918,7 @@ { "cell_type": "code", "execution_count": 138, - "id": "c9bc1cda", + "id": "437605af", "metadata": {}, "outputs": [ { @@ -3939,7 +3939,7 @@ { "cell_type": "code", "execution_count": 139, - "id": "af4ddce9", + "id": "1e9f160b", "metadata": {}, "outputs": [ { @@ -3960,7 +3960,7 @@ { "cell_type": "code", "execution_count": 140, - "id": "0bd0e82c", + "id": "e209d12a", "metadata": {}, "outputs": [ { @@ -3981,7 +3981,7 @@ { "cell_type": "code", "execution_count": 141, - "id": "5b1b68e8", + "id": "8f574141", "metadata": {}, "outputs": [ { @@ -4001,7 +4001,7 @@ }, { "cell_type": "markdown", - "id": "c501b6b5", + "id": "c1eed605", "metadata": {}, "source": [ "### Flat Iterator indexing\n", @@ -4016,7 +4016,7 @@ { "cell_type": "code", "execution_count": 142, - "id": "0a9c0a1d", + "id": "5ac958b9", "metadata": {}, "outputs": [], "source": [ @@ -4026,7 +4026,7 @@ }, { "cell_type": "markdown", - "id": "a820c27b", + "id": "e5fa14f1", "metadata": {}, "source": [ "Or an array of the right size:" @@ -4035,7 +4035,7 @@ { "cell_type": "code", "execution_count": 143, - "id": "67e67af8", + "id": "03e4fa34", "metadata": {}, "outputs": [], "source": [ @@ -4044,7 +4044,7 @@ }, { "cell_type": "markdown", - "id": "a834aaaf", + "id": "48b8957e", "metadata": {}, "source": [ "Note that assignments may result in changes if assigning higher types to lower types (like floats to ints) or even exceptions (assigning complex to floats or ints):" @@ -4053,7 +4053,7 @@ { "cell_type": "code", "execution_count": 144, - "id": "90ccb7f8", + "id": "78392572", "metadata": {}, "outputs": [ { @@ -4074,7 +4074,7 @@ }, { "cell_type": "markdown", - "id": "069aa7ba", + "id": "2d6aec14", "metadata": {}, "source": [ "```py\n", @@ -4093,7 +4093,7 @@ { "cell_type": "code", "execution_count": 145, - "id": "2429eb5c", + "id": "817f4e56", "metadata": {}, "outputs": [ { @@ -4115,7 +4115,7 @@ { "cell_type": "code", "execution_count": 146, - "id": "a6b44846", + "id": "8d24f864", "metadata": {}, "outputs": [ { @@ -4136,7 +4136,7 @@ }, { "cell_type": "markdown", - "id": "95d8ed89", + "id": "fc9b6b02", "metadata": {}, "source": [ "Where people expect that the 1st location will be incremented by 3. In fact, it will only be incremented by 1. The reason is that a new array is extracted from the original (as a temporary) containing the values at 1, 1, 3, 1, then the value 1 is added to the temporary, and then the temporary is assigned back to the original array. Thus the value of the array at `x[1] + 1` is assigned to `x[1]` three times, rather than being incremented 3 times.\n", @@ -4149,7 +4149,7 @@ { "cell_type": "code", "execution_count": 147, - "id": "cd246fe5", + "id": "fcf9c20a", "metadata": {}, "outputs": [ { @@ -4171,7 +4171,7 @@ }, { "cell_type": "markdown", - "id": "2c552db9", + "id": "86f6e843", "metadata": {}, "source": [ "So one can use code to construct tuples of any number of indices and then use these within an index.\n", @@ -4182,7 +4182,7 @@ { "cell_type": "code", "execution_count": 148, - "id": "57f76597", + "id": "13b4d1e0", "metadata": {}, "outputs": [ { @@ -4203,7 +4203,7 @@ }, { "cell_type": "markdown", - "id": "8f04c7f3", + "id": "159319b6", "metadata": {}, "source": [ "Likewise, ellipsis can be specified by code by using the Ellipsis object:" @@ -4212,7 +4212,7 @@ { "cell_type": "code", "execution_count": 149, - "id": "fae6ef2a", + "id": "9ca410fa", "metadata": {}, "outputs": [ { @@ -4235,7 +4235,7 @@ }, { "cell_type": "markdown", - "id": "311bc41b", + "id": "767a18dd", "metadata": {}, "source": [ "For this reason, it is possible to use the output from the `np.nonzero()` function directly as an index since it always returns a tuple of index arrays.\n", @@ -4246,7 +4246,7 @@ { "cell_type": "code", "execution_count": 150, - "id": "25b456d8", + "id": "2580ea87", "metadata": {}, "outputs": [ { @@ -4316,7 +4316,7 @@ { "cell_type": "code", "execution_count": 151, - "id": "0581674b", + "id": "a9876d42", "metadata": {}, "outputs": [ { @@ -4336,7 +4336,7 @@ }, { "cell_type": "markdown", - "id": "facacecd", + "id": "e878b8e8", "metadata": {}, "source": [ "## Structured arrays\n", @@ -4349,7 +4349,7 @@ { "cell_type": "code", "execution_count": 152, - "id": "c82e36f6", + "id": "4c4c0611", "metadata": {}, "outputs": [ { @@ -4372,7 +4372,7 @@ }, { "cell_type": "markdown", - "id": "5ed96385", + "id": "6df07549", "metadata": {}, "source": [ "Here `x` is a one-dimensional array of length two whose datatype is a structure with three fields: 1. A string of length 10 or less named `'name'`, 2. a 32-bit integer named `'age'`, and 3. a 32-bit float named `'weight'`.\n", @@ -4383,7 +4383,7 @@ { "cell_type": "code", "execution_count": 153, - "id": "4ccad27f", + "id": "842831f0", "metadata": {}, "outputs": [ { @@ -4403,7 +4403,7 @@ }, { "cell_type": "markdown", - "id": "4aefa26a", + "id": "72ddac9c", "metadata": {}, "source": [ "You can access and modify individual fields of a structured array by indexing with the field name:" @@ -4412,7 +4412,7 @@ { "cell_type": "code", "execution_count": 154, - "id": "5d173699", + "id": "e34d9aa7", "metadata": {}, "outputs": [ { @@ -4433,7 +4433,7 @@ { "cell_type": "code", "execution_count": 155, - "id": "6b6a4200", + "id": "126b416f", "metadata": {}, "outputs": [ { @@ -4454,7 +4454,7 @@ { "cell_type": "code", "execution_count": 156, - "id": "da8b24f8", + "id": "912cad13", "metadata": {}, "outputs": [ { @@ -4475,7 +4475,7 @@ }, { "cell_type": "markdown", - "id": "5ab9fdd5", + "id": "ca9d77da", "metadata": {}, "source": [ "Structured datatypes are designed to be able to mimic 'structs' in the C language, and share a similar memory layout. They are meant for interfacing with C code and for low-level manipulation of structured buffers, for example for interpreting binary blobs. For these purposes they support specialized features such as subarrays, nested datatypes, and unions, and allow control over the memory layout of the structure.\n", @@ -4498,7 +4498,7 @@ { "cell_type": "code", "execution_count": 157, - "id": "c2e8cc01", + "id": "a651d2ac", "metadata": {}, "outputs": [ { @@ -4518,7 +4518,7 @@ }, { "cell_type": "markdown", - "id": "632de1e0", + "id": "85665077", "metadata": {}, "source": [ "If `fieldname` is the empty string `''`, the field will be given a default name of the form `f#`, where `#` is the integer index of the field, counting from 0 from the left:" @@ -4527,7 +4527,7 @@ { "cell_type": "code", "execution_count": 158, - "id": "b7600f3c", + "id": "5bfb5622", "metadata": {}, "outputs": [ { @@ -4547,7 +4547,7 @@ }, { "cell_type": "markdown", - "id": "ebeaece6", + "id": "7d7bda10", "metadata": {}, "source": [ "The byte offsets of the fields within the structure and the total structure itemsize are determined automatically.\n", @@ -4560,7 +4560,7 @@ { "cell_type": "code", "execution_count": 159, - "id": "b6d2bc6e", + "id": "dbfc5653", "metadata": {}, "outputs": [ { @@ -4581,7 +4581,7 @@ { "cell_type": "code", "execution_count": 160, - "id": "f7c6fefc", + "id": "9215972d", "metadata": {}, "outputs": [ { @@ -4601,7 +4601,7 @@ }, { "cell_type": "markdown", - "id": "8c10e670", + "id": "f22664b6", "metadata": {}, "source": [ "- A dictionary of field parameter arrays\n", @@ -4614,7 +4614,7 @@ { "cell_type": "code", "execution_count": 161, - "id": "c2d32750", + "id": "584c9e57", "metadata": {}, "outputs": [ { @@ -4635,7 +4635,7 @@ { "cell_type": "code", "execution_count": 162, - "id": "d1cbfcb0", + "id": "96debf43", "metadata": {}, "outputs": [ { @@ -4658,7 +4658,7 @@ }, { "cell_type": "markdown", - "id": "f7e5b2a3", + "id": "87a73b3e", "metadata": {}, "source": [ "Offsets may be chosen such that the fields overlap, though this will mean that assigning to one field may clobber any overlapping field’s data. As an exception, fields of `numpy.object_` type cannot overlap with other fields, because of the risk of clobbering the internal object pointer and then dereferencing it.\n", @@ -4673,7 +4673,7 @@ { "cell_type": "code", "execution_count": 163, - "id": "43546b17", + "id": "bb4ad3d2", "metadata": {}, "outputs": [ { @@ -4693,7 +4693,7 @@ }, { "cell_type": "markdown", - "id": "a6e46def", + "id": "394a0bce", "metadata": {}, "source": [ "#### Manipulating and Displaying Structured Datatypes\n", @@ -4704,7 +4704,7 @@ { "cell_type": "code", "execution_count": 164, - "id": "550f4247", + "id": "8da55622", "metadata": {}, "outputs": [ { @@ -4725,7 +4725,7 @@ }, { "cell_type": "markdown", - "id": "31887a1c", + "id": "ef61254c", "metadata": {}, "source": [ "The field names may be modified by assigning to the `names` attribute using a sequence of strings of the same length.\n", @@ -4736,7 +4736,7 @@ { "cell_type": "code", "execution_count": 165, - "id": "76f47ecb", + "id": "35e677f7", "metadata": {}, "outputs": [ { @@ -4756,7 +4756,7 @@ }, { "cell_type": "markdown", - "id": "9e465f96", + "id": "5b0965e6", "metadata": {}, "source": [ "Both the `names` and `fields` attributes will equal `None` for unstructured arrays. The recommended way to test if a dtype is structured is with `if dt.names is not None` rather than `if dt.names`, to account for dtypes with 0 fields.\n", @@ -4773,7 +4773,7 @@ { "cell_type": "code", "execution_count": 166, - "id": "23295543", + "id": "808b8e57", "metadata": {}, "outputs": [ { @@ -4793,7 +4793,7 @@ }, { "cell_type": "markdown", - "id": "fe463767", + "id": "102ab5a9", "metadata": {}, "source": [ "When using the first form of dictionary-based specification, the titles may be supplied as an extra `'titles'` key as described above. When using the second (discouraged) dictionary-based specification, the title can be supplied by providing a 3-element tuple `(datatype, offset, title)` instead of the usual 2-element tuple:" @@ -4802,7 +4802,7 @@ { "cell_type": "code", "execution_count": 167, - "id": "8e23d763", + "id": "5e2bdf5e", "metadata": {}, "outputs": [ { @@ -4822,7 +4822,7 @@ }, { "cell_type": "markdown", - "id": "01baea80", + "id": "5dc79104", "metadata": {}, "source": [ "The `dtype.fields` dictionary will contain titles as keys, if any titles are used. This means effectively that a field with a title will be represented twice in the fields dictionary. The tuple values for these fields will also have a third element, the field title. Because of this, and because the `names` attribute preserves the field order while the `fields` attribute may not, it is recommended to iterate through the fields of a dtype using the `names` attribute of the dtype, which will not list titles, as in:" @@ -4831,7 +4831,7 @@ { "cell_type": "code", "execution_count": 168, - "id": "627ad17a", + "id": "8a797059", "metadata": {}, "outputs": [ { @@ -4850,7 +4850,7 @@ }, { "cell_type": "markdown", - "id": "2d5fed8f", + "id": "16de7203", "metadata": {}, "source": [ "### Indexing and Assignment to Structured arrays\n", @@ -4867,7 +4867,7 @@ { "cell_type": "code", "execution_count": 169, - "id": "75b4faf5", + "id": "b3c0653e", "metadata": {}, "outputs": [ { @@ -4890,7 +4890,7 @@ }, { "cell_type": "markdown", - "id": "bde6cbab", + "id": "e3161555", "metadata": {}, "source": [ "##### Assignment from Scalars\n", @@ -4901,7 +4901,7 @@ { "cell_type": "code", "execution_count": 170, - "id": "cbcd09b8", + "id": "3a8d4e40", "metadata": {}, "outputs": [], "source": [ @@ -4911,7 +4911,7 @@ { "cell_type": "code", "execution_count": 171, - "id": "e53e877a", + "id": "48873091", "metadata": {}, "outputs": [ { @@ -4934,7 +4934,7 @@ { "cell_type": "code", "execution_count": 172, - "id": "ee132ce3", + "id": "0f6129f7", "metadata": {}, "outputs": [ { @@ -4956,7 +4956,7 @@ }, { "cell_type": "markdown", - "id": "3bc68cc5", + "id": "2e114197", "metadata": {}, "source": [ "Structured arrays can also be assigned to unstructured arrays, but only if the structured datatype has just a single field:" @@ -4965,7 +4965,7 @@ { "cell_type": "code", "execution_count": 173, - "id": "6b80b416", + "id": "1e817a2d", "metadata": {}, "outputs": [], "source": [ @@ -4976,7 +4976,7 @@ { "cell_type": "code", "execution_count": 174, - "id": "eb7d3420", + "id": "b276510e", "metadata": {}, "outputs": [], "source": [ @@ -4985,7 +4985,7 @@ }, { "cell_type": "markdown", - "id": "4554b2a4", + "id": "d6cb1be7", "metadata": {}, "source": [ "```py\n", @@ -5006,7 +5006,7 @@ { "cell_type": "code", "execution_count": 175, - "id": "ec0922f5", + "id": "86c62c21", "metadata": {}, "outputs": [], "source": [ @@ -5017,7 +5017,7 @@ { "cell_type": "code", "execution_count": 176, - "id": "29f4eea2", + "id": "c00582b0", "metadata": {}, "outputs": [ { @@ -5039,7 +5039,7 @@ }, { "cell_type": "markdown", - "id": "26eb2c63", + "id": "66dbb2d7", "metadata": {}, "source": [ "##### Assignment involving subarrays\n", @@ -5056,7 +5056,7 @@ { "cell_type": "code", "execution_count": 177, - "id": "cd694ccf", + "id": "7ab77ab8", "metadata": {}, "outputs": [ { @@ -5078,7 +5078,7 @@ { "cell_type": "code", "execution_count": 178, - "id": "b7c8796b", + "id": "1512b7c1", "metadata": {}, "outputs": [ { @@ -5099,7 +5099,7 @@ }, { "cell_type": "markdown", - "id": "85a10b43", + "id": "1f9b14bd", "metadata": {}, "source": [ "The resulting array is a view into the original array. It shares the same memory locations and writing to the view will modify the original array." @@ -5108,7 +5108,7 @@ { "cell_type": "code", "execution_count": 179, - "id": "acfd1a61", + "id": "7408fddd", "metadata": {}, "outputs": [ { @@ -5130,7 +5130,7 @@ }, { "cell_type": "markdown", - "id": "f963c0a3", + "id": "5857f0c1", "metadata": {}, "source": [ "This view has the same dtype and itemsize as the indexed field, so it is typically a non-structured array, except in the case of nested structures." @@ -5139,7 +5139,7 @@ { "cell_type": "code", "execution_count": 180, - "id": "72bfa1e0", + "id": "5aa16f19", "metadata": {}, "outputs": [ { @@ -5159,7 +5159,7 @@ }, { "cell_type": "markdown", - "id": "10b66686", + "id": "3e10749c", "metadata": {}, "source": [ "If the accessed field is a subarray, the dimensions of the subarray are appended to the shape of the result:" @@ -5168,7 +5168,7 @@ { "cell_type": "code", "execution_count": 181, - "id": "d9fbe3ed", + "id": "62e622e5", "metadata": {}, "outputs": [], "source": [ @@ -5178,7 +5178,7 @@ { "cell_type": "code", "execution_count": 182, - "id": "e125e942", + "id": "7a7ff9ff", "metadata": {}, "outputs": [ { @@ -5199,7 +5199,7 @@ { "cell_type": "code", "execution_count": 183, - "id": "110452d7", + "id": "c81fc737", "metadata": {}, "outputs": [ { @@ -5219,7 +5219,7 @@ }, { "cell_type": "markdown", - "id": "067eca08", + "id": "0c7fbe27", "metadata": {}, "source": [ "##### Accessing multiple fields\n", @@ -5232,7 +5232,7 @@ { "cell_type": "code", "execution_count": 184, - "id": "f45d5149", + "id": "ae1f0721", "metadata": {}, "outputs": [ { @@ -5254,7 +5254,7 @@ }, { "cell_type": "markdown", - "id": "c5ad8dd0", + "id": "dc1fdde2", "metadata": {}, "source": [ "Assignment to the view modifies the original array. The view’s fields will be in the order they were indexed. Note that unlike for single-field indexing, the dtype of the view has the same itemsize as the original array, and has fields at the same offsets as in the original array, and unindexed fields are merely missing.\n", @@ -5265,7 +5265,7 @@ { "cell_type": "code", "execution_count": 185, - "id": "6a8b3d59", + "id": "85fe6386", "metadata": {}, "outputs": [ { @@ -5287,7 +5287,7 @@ }, { "cell_type": "markdown", - "id": "1993de1f", + "id": "83513e05", "metadata": {}, "source": [ "This obeys the structured array assignment rules described above. For example, this means that one can swap the values of two fields using appropriate multi-field indexes:" @@ -5296,7 +5296,7 @@ { "cell_type": "code", "execution_count": 186, - "id": "6ba06dd0", + "id": "d6698eb0", "metadata": {}, "outputs": [], "source": [ @@ -5305,7 +5305,7 @@ }, { "cell_type": "markdown", - "id": "36f03b8a", + "id": "cd8e9380", "metadata": {}, "source": [ "##### Indexing with an integer to get a structured scalar\n", @@ -5316,7 +5316,7 @@ { "cell_type": "code", "execution_count": 187, - "id": "aa4d413d", + "id": "dd10ae37", "metadata": {}, "outputs": [ { @@ -5339,7 +5339,7 @@ { "cell_type": "code", "execution_count": 188, - "id": "65efac41", + "id": "2dd9edfd", "metadata": {}, "outputs": [ { @@ -5359,7 +5359,7 @@ }, { "cell_type": "markdown", - "id": "15a6d29e", + "id": "7021926f", "metadata": {}, "source": [ "Unlike other numpy scalars, structured scalars are mutable and act like views into the original array, such that modifying the scalar will modify the original array. Structured scalars also support access and assignment by field name:" @@ -5368,7 +5368,7 @@ { "cell_type": "code", "execution_count": 189, - "id": "e5433407", + "id": "38025152", "metadata": {}, "outputs": [ { @@ -5391,7 +5391,7 @@ }, { "cell_type": "markdown", - "id": "791b2a6e", + "id": "267858ca", "metadata": {}, "source": [ "Similarly to tuples, structured scalars can also be indexed with an integer:" @@ -5400,7 +5400,7 @@ { "cell_type": "code", "execution_count": 190, - "id": "3593e923", + "id": "df9a2bb5", "metadata": {}, "outputs": [ { @@ -5422,7 +5422,7 @@ { "cell_type": "code", "execution_count": 191, - "id": "797c52c8", + "id": "a4d18340", "metadata": {}, "outputs": [], "source": [ @@ -5431,7 +5431,7 @@ }, { "cell_type": "markdown", - "id": "febc77a1", + "id": "c04f3aa0", "metadata": {}, "source": [ "Thus, tuples might be thought of as the native Python equivalent to numpy’s structured types, much like native python integers are the equivalent to numpy’s integer types. Structured scalars may be converted to a tuple by calling `numpy.ndarray.item`:" @@ -5440,7 +5440,7 @@ { "cell_type": "code", "execution_count": 192, - "id": "0fd86175", + "id": "44d4f5b2", "metadata": {}, "outputs": [ { @@ -5460,7 +5460,7 @@ }, { "cell_type": "markdown", - "id": "32b69b12", + "id": "f30dc4b7", "metadata": {}, "source": [ "#### Viewing structured arrays containing objects\n", @@ -5475,7 +5475,7 @@ { "cell_type": "code", "execution_count": 193, - "id": "ecd3e689", + "id": "4fd31f79", "metadata": {}, "outputs": [ { @@ -5497,7 +5497,7 @@ }, { "cell_type": "markdown", - "id": "af2cb3cd", + "id": "424d1ba7", "metadata": {}, "source": [ "NumPy will promote individual field datatypes to perform the comparison. So the following is also valid (note the `'f4'` dtype for the `'a'` field):" @@ -5506,7 +5506,7 @@ { "cell_type": "code", "execution_count": 194, - "id": "672c39a2", + "id": "baaa67b7", "metadata": {}, "outputs": [ { @@ -5527,7 +5527,7 @@ }, { "cell_type": "markdown", - "id": "1bab8dc6", + "id": "80b3e916", "metadata": {}, "source": [ "To compare two structured arrays, it must be possible to promote them to a common dtype as returned by `numpy.result_type` and `np.promote_types`. This enforces that the number of fields, the field names, and the field titles must match precisely. When promotion is not possible, for example due to mismatching field names, NumPy will raise an error. Promotion between two structured dtypes results in a canonical dtype that ensures native byte-order for all fields:" @@ -5536,7 +5536,7 @@ { "cell_type": "code", "execution_count": 195, - "id": "5a895b7b", + "id": "84e4108a", "metadata": {}, "outputs": [ { @@ -5557,7 +5557,7 @@ { "cell_type": "code", "execution_count": 196, - "id": "a9b85563", + "id": "c3f17d88", "metadata": {}, "outputs": [ { @@ -5577,7 +5577,7 @@ }, { "cell_type": "markdown", - "id": "559e4ec0", + "id": "cb87b09c", "metadata": {}, "source": [ "The resulting dtype from promotion is also guaranteed to be packed, meaning that all fields are ordered contiguously and any unnecessary padding is removed:" @@ -5586,7 +5586,7 @@ { "cell_type": "code", "execution_count": 197, - "id": "90507c63", + "id": "20a61efb", "metadata": {}, "outputs": [ { @@ -5608,7 +5608,7 @@ { "cell_type": "code", "execution_count": 198, - "id": "560bb176", + "id": "cf3b4857", "metadata": {}, "outputs": [ { @@ -5628,7 +5628,7 @@ }, { "cell_type": "markdown", - "id": "087c3eaf", + "id": "9f4e3590", "metadata": {}, "source": [ "Note that the result prints without `offsets` or `itemsize` indicating no additional padding. If a structured dtype is created with `align=True` ensuring that `dtype.isalignedstruct` is true, this property is preserved:" @@ -5637,7 +5637,7 @@ { "cell_type": "code", "execution_count": 199, - "id": "cdab5905", + "id": "6363970b", "metadata": {}, "outputs": [ { @@ -5659,7 +5659,7 @@ { "cell_type": "code", "execution_count": 200, - "id": "6b9498d3", + "id": "e000dc13", "metadata": {}, "outputs": [ { @@ -5680,7 +5680,7 @@ { "cell_type": "code", "execution_count": 201, - "id": "a51a7440", + "id": "b47c2d91", "metadata": {}, "outputs": [ { @@ -5700,7 +5700,7 @@ }, { "cell_type": "markdown", - "id": "ebdd7ede", + "id": "fad22d96", "metadata": {}, "source": [ "When promoting multiple dtypes, the result is aligned if any of the inputs is:" @@ -5709,7 +5709,7 @@ { "cell_type": "code", "execution_count": 202, - "id": "a9cf2e32", + "id": "12393ade", "metadata": {}, "outputs": [ { @@ -5729,7 +5729,7 @@ }, { "cell_type": "markdown", - "id": "7dcadc00", + "id": "4a7da9ec", "metadata": {}, "source": [ "The `<` and `>` operators always return `False` when comparing void structured arrays, and arithmetic and bitwise operations are not supported.\n", diff --git a/_sources/prerequisites/python-programming-basics.ipynb b/_sources/prerequisites/python-programming-basics.ipynb index d277e404e..26e6b9080 100644 --- a/_sources/prerequisites/python-programming-basics.ipynb +++ b/_sources/prerequisites/python-programming-basics.ipynb @@ -4,14 +4,18 @@ "cell_type": "code", "execution_count": null, "id": "16159125", - "metadata": {}, + "metadata": { + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "# Install the necessary dependencies\n", "\n", "import sys\n", "import os\n", - "!{sys.executable} -m pip install --quiet jupyterlab_myst ipython" + "!{sys.executable} -m pip install --quiet jupyterlab_myst ipython pytest" ] }, { @@ -68,8 +72,14 @@ "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n", "SOFTWARE.\n", "\n", - "\n", - "\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "bda5c0cb", + "metadata": {}, + "source": [ "# Python programming basics\n", "\n", "## Python syntax\n", diff --git a/_sources/prerequisites/python-programming-introduction.ipynb b/_sources/prerequisites/python-programming-introduction.ipynb index 4f8bf002a..a142cebcf 100644 --- a/_sources/prerequisites/python-programming-introduction.ipynb +++ b/_sources/prerequisites/python-programming-introduction.ipynb @@ -4,7 +4,11 @@ "cell_type": "code", "execution_count": null, "id": "55db1b3f", - "metadata": {}, + "metadata": { + "tags": [ + "hide-input" + ] + }, "outputs": [], "source": [ "# Install the necessary dependencies\n", @@ -67,23 +71,7 @@ "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n", "SOFTWARE.\n", "\n", - "\n", - "\n", - "# Python programming basics\n", - "\n", - "## Python syntax\n", - "\n", - "**Python syntax compared to other programming languages**\n", - "\n", - "- Python was designed for readability and has some similarities to the English language with influence from mathematics.\n", - "- Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.\n", - "- Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly brackets for this purpose.\n", - "\n", - "### Python indentations\n", - "\n", - "While in other programming languages the indentation in code is for readability only, in Python the indentation is very important.\n", - "\n", - "Python uses indentation to indicate a block of code." + "" ] }, { diff --git a/assignments/README.html b/assignments/README.html index bdf4c818b..f0a8ef7a2 100644 --- a/assignments/README.html +++ b/assignments/README.html @@ -6,7 +6,7 @@ - 41. Self-paced assignments — Ocademy Open Machine Learning Book + 40. Self-paced assignments — Ocademy Open Machine Learning Book @@ -98,8 +98,8 @@ - - + + @@ -159,17 +159,17 @@

Ocademy Open Machine Learning Book

@@ -181,7 +181,7 @@

Ocademy Open Machine Learning Book

@@ -370,17 +370,17 @@

Ocademy Open Machine Learning Book