<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@b9154422bed64bd6ad73917ba574e33a" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@808fa4d229ca444b9ed9ca1810ca973a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@808fa4d229ca444b9ed9ca1810ca973a" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<p style="text-align: left;">This section contains possible solutions to the exercises posed in the Python basics module. There is more than one correct solution for most of the exercises so these answers are for reference only.</p>
<p style="text-align: left;"><a class="reference external" href="/assets/courseware/v1/68dc5750b88bc742b53e5c8fcaae44c6/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block/06_download-python_solutions.ipynb" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer;" target="[object Object]">Download the exercise solutions notebook</a></p>
<p style="text-align: left;">To view the solutions as an interactive notebook, download the file to your machine and upload it to the Sandbox as in the Python basics lessons.</p>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@4b6208579b8240e3a82da5d609fc4b49" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@cd1fe379436b4ee7b03e16f28f8ece17">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@cd1fe379436b4ee7b03e16f28f8ece17" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<section id="1.1-Fill-the-asterisk-line-with-your-name-and-run-the-cell." style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699; text-align: left;">1.1 Fill the asterisk line with your name and run the cell.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#1.1-Fill-the-asterisk-line-with-your-name-and-run-the-cell." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px; text-align: left;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[1]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px; text-align: left;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Fill the ****** space with your name and run the cell.</span>
<span class="n" style="box-sizing: border-box;">message</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="s2" style="box-sizing: border-box; color: #ba2121;">"My name is Python"</span>
<span class="n" style="box-sizing: border-box;">message</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none; text-align: left;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[1]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset; text-align: left;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">'My name is Python'
</pre>
</div>
</div>
</div>
</section>
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699; text-align: left;">1.2 You can add new cells to insert new code at any point in a notebook. Click on the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">+</span></code> icon in the top menu to add a new cell below the current one. Add a new cell below the next cell, and use it to print the value of variable <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">a</span></code>.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#1.2-You-can-add-new-cells-to-insert-new-code-at-any-point-in-a-notebook.-Click-on-the-+-icon-in-the-top-menu-to-add-a-new-cell-below-the-current-one.-Add-a-new-cell-below-the-next-cell,-and-use-it-to-print-the-value-of-variable-a." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px; text-align: left;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[2]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px; text-align: left;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">a</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="mi" style="box-sizing: border-box; color: #666666;">365</span><span class="o" style="box-sizing: border-box; color: #666666;">*</span><span class="mi" style="box-sizing: border-box; color: #666666;">24</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Add a new cell just below this one. Use it to print the value of variable `a`</span>
</pre>
</div>
</div>
</div>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 0px; width: 696.469px; padding-top: 5px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[3]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">a</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none; text-align: left;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[3]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset; text-align: left;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">8760
</pre>
</div>
</div>
</div>
<p style="box-sizing: border-box; text-align: left;"><strong>Question:</strong> Now what happens if you scroll back up the notebook and execute a different cell containing <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">print(a)</span></code>?</p>
<p style="text-align: left;"><strong style="box-sizing: border-box;">Answer:</strong> It should now print <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">8760</span></code> as ‘global state’ means the value of <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">a</span></code> has been changed.</p>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@882aba91e7ba4c0c99b7d5c628442550" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@f2fa3dd73f194726b15e57764bcda53b">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@f2fa3dd73f194726b15e57764bcda53b" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[4]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">numpy</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">np</span>
</pre>
</div>
</div>
</div>
<section id="2.1-Use-the-numpy-add-function-to-add-the-values-34-and-29-in-the-cell-below." style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">2.1 Use the numpy <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">add</span></code> function to add the values <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">34</span></code> and <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">29</span></code> in the cell below.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#2.1-Use-the-numpy-add-function-to-add-the-values-34-and-29-in-the-cell-below." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[5]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Use numpy add to add 34 and 29</span>
<span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">add</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">34</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">29</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[5]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">63
</pre>
</div>
</div>
</div>
</section>
<section id="2.2-Declare-a-new-array-with-contents-[5,4,3,2,1]-and-slice-it-to-select-the-last-3-items." style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">2.2 Declare a new array with contents [5,4,3,2,1] and slice it to select the last 3 items.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#2.2-Declare-a-new-array-with-contents-[5,4,3,2,1]-and-slice-it-to-select-the-last-3-items." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[6]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Substitute the ? symbols by the correct expressions and values</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Declare the array</span>
<span class="n" style="box-sizing: border-box;">arr</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">array</span><span class="p" style="box-sizing: border-box;">([</span><span class="mi" style="box-sizing: border-box; color: #666666;">5</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">4</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">2</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">])</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Slice array for the last 3 items only</span>
<span class="n" style="box-sizing: border-box;">arr</span><span class="p" style="box-sizing: border-box;">[</span><span class="o" style="box-sizing: border-box; color: #666666;">-</span><span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">:]</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[6]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">array([3, 2, 1])
</pre>
</div>
</div>
</div>
</section>
<section id="2.3:-Select-all-the-elements-in-the-array-below-excluding-the-last-one,-[15]." style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">2.3: Select all the elements in the array below excluding the last one, <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">[15]</span></code>.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#2.3:-Select-all-the-elements-in-the-array-below-excluding-the-last-one,-[15]." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[7]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">arr</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">array</span><span class="p" style="box-sizing: border-box;">([</span><span class="mi" style="box-sizing: border-box; color: #666666;">0</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">2</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">4</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">5</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">6</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">7</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">8</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">9</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">10</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">11</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">12</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">13</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">14</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">15</span><span class="p" style="box-sizing: border-box;">])</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Substitute the ? symbols by the correct expressions and values</span>
<span class="n" style="box-sizing: border-box;">arr</span><span class="p" style="box-sizing: border-box;">[:</span><span class="o" style="box-sizing: border-box; color: #666666;">-</span><span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">]</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[7]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])
</pre>
</div>
</div>
</div>
</section>
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">2.4 Use <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">arr</span></code> as defined in 2.3. Exclude the last element from the list, but now only select every 3rd element. Remember the third index indicates <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">stride</span></code>, if used.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#2.4-Use-arr-as-defined-in-2.3.-Exclude-the-last-element-from-the-list,-but-now-only-select-every-3rd-element.-Remember-the-third-index-indicates-stride,-if-used." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<p style="box-sizing: border-box; color: #000000; text-align: left;"><strong style="box-sizing: border-box;">Hint:</strong> The result should be <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">[0,3,6,9,12]</span></code>.</p>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;">[8]:</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Substitute the ? symbols by the correct expressions and values</span>
<span class="n" style="box-sizing: border-box;">arr</span><span class="p" style="box-sizing: border-box;">[:</span><span class="o" style="box-sizing: border-box; color: #666666;">-</span><span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">]</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[8]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">array([ 0, 3, 6, 9, 12])
</pre>
</div>
</div>
</div>
<section id="2.5-You'll-need-to-combine-array-comparisons-and-logical-operators-to-solve-this-one.-Find-out-the-values-in-the-following-array-that-are-greater-than-3-AND-less-than-7.-The-output-should-be-a-boolean-array." style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">2.5 You’ll need to combine array comparisons and logical operators to solve this one. Find out the values in the following array that are greater than <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">3</span></code> AND less than <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">7</span></code>. The output should be a boolean array.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#2.5-You'll-need-to-combine-array-comparisons-and-logical-operators-to-solve-this-one.-Find-out-the-values-in-the-following-array-that-are-greater-than-3-AND-less-than-7.-The-output-should-be-a-boolean-array." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<p style="box-sizing: border-box; text-align: left;"><strong style="box-sizing: border-box;">Hint:</strong> If you are stuck, reread the section on boolean arrays.</p>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[9]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">arr</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">array</span><span class="p" style="box-sizing: border-box;">([</span><span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">5</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">6</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">5</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">7</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">])</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Use array comparisons (<, >, etc.) and logical operators (*, +) to find where</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># the values are greater than 3 and less than 7.</span>
<span class="n" style="box-sizing: border-box;">boolean_array</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr</span> <span class="o" style="box-sizing: border-box; color: #666666;">></span> <span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; color: #666666;">*</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr</span> <span class="o" style="box-sizing: border-box; color: #666666;"><</span> <span class="mi" style="box-sizing: border-box; color: #666666;">7</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[10]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">boolean_array</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[10]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">array([False, False, True, False, True, False, False, True, False,
False])
</pre>
</div>
</div>
</div>
</section>
<section id="2.6-Use-your-boolean-array-from-2.5-to-mask-the-False-values-from-arr." style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">2.6 Use your boolean array from 2.5 to mask the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">False</span></code> values from <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">arr</span></code>.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#2.6-Use-your-boolean-array-from-2.5-to-mask-the-False-values-from-arr." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<p style="box-sizing: border-box; text-align: left;"><strong style="box-sizing: border-box;">Hint:</strong> The result should be <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">[5,</span> <span class="pre" style="box-sizing: border-box;">6,</span> <span class="pre" style="box-sizing: border-box;">5]</span></code>.</p>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[11]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Use your resulting boolean_array array from 2.5</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># to mask arr as defined in 2.5</span>
<span class="n" style="box-sizing: border-box;">arr</span><span class="p" style="box-sizing: border-box;">[</span><span class="n" style="box-sizing: border-box;">boolean_array</span><span class="p" style="box-sizing: border-box;">]</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[11]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">array([5, 6, 5])</pre>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@0324749a5efc4af986b0f61d1af4ec54" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@851c9e14fac747328cfb3fecfe1d68d8">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@851c9e14fac747328cfb3fecfe1d68d8" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[12]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="o" style="box-sizing: border-box; color: #666666;">%</span><span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">matplotlib</span> inline
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">numpy</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">np</span>
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">from</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">matplotlib</span> <span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">pyplot</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="n" style="box-sizing: border-box;">plt</span>
<span class="n" style="box-sizing: border-box;">im</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">copy</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imread</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #ba2121;">'Guinea_Bissau.JPG'</span><span class="p" style="box-sizing: border-box;">))</span>
</pre>
</div>
</div>
</div>
<section id="3.1-Let's-use-the-indexing-functionality-of-numpy-to-select-a-portion-of-this-image.-Select-the-top-right-corner-of-this-image-with-shape-(200,200)." style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">3.1 Let’s use the indexing functionality of numpy to select a portion of this image. Select the top-right corner of this image with shape <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">(200,200)</span></code>.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#3.1-Let's-use-the-indexing-functionality-of-numpy-to-select-a-portion-of-this-image.-Select-the-top-right-corner-of-this-image-with-shape-(200,200)." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<p style="box-sizing: border-box; text-align: left;"><strong style="box-sizing: border-box;">Hint:</strong> Remember there are three dimensions in this image. Colons separate spans, and commas separate dimensions.</p>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[13]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Both options below are correct</span>
<span class="n" style="box-sizing: border-box;">topright</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">im</span><span class="p" style="box-sizing: border-box;">[:</span><span class="mi" style="box-sizing: border-box; color: #666666;">200</span><span class="p" style="box-sizing: border-box;">,</span> <span class="o" style="box-sizing: border-box; color: #666666;">-</span><span class="mi" style="box-sizing: border-box; color: #666666;">200</span><span class="p" style="box-sizing: border-box;">:,</span> <span class="p" style="box-sizing: border-box;">]</span>
<span class="n" style="box-sizing: border-box;">topright</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">im</span><span class="p" style="box-sizing: border-box;">[:</span><span class="mi" style="box-sizing: border-box; color: #666666;">200</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">400</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">600</span><span class="p" style="box-sizing: border-box;">,</span> <span class="p" style="box-sizing: border-box;">]</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Plot your result using imshow</span>
<span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">topright</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[13]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.image.AxesImage at 0x7f08e28f7940>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_06_python_solutions_27_1.png" src="https://training.digitalearthafrica.org/en/latest/_images/python_basics_06_python_solutions_27_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px;" /></div>
</div>
</section>
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">3.2 Let’s have a look at one of the pixels in this image. We choose the top-left corner with position <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">(0,0)</span></code> and show the values of its RGB channels.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#3.2-Let's-have-a-look-at-one-of-the-pixels-in-this-image.-We-choose-the-top-left-corner-with-position-(0,0)-and-show-the-values-of-its-RGB-channels." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px; text-align: left;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[14]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px; text-align: left;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Run this cell to see the colour channel values</span>
<span class="n" style="box-sizing: border-box;">im</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">0</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">0</span><span class="p" style="box-sizing: border-box;">]</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none; text-align: left;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[14]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset; text-align: left;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">array([249, 196, 104], dtype=uint8)
</pre>
</div>
</div>
</div>
<p style="text-align: left;">The first value corresponds to the red component, the second to the green and the third to the blue. <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">uint8</span></code> can contain values in the range <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">[0-255]</span></code> so the pixel has a lot of red, some green, and not much blue. This pixel is a orange-yellow sandy colour. Now let’s modify the image.</p>
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699; text-align: left;">3.3 What happens if we set all the values representing the blue channel to the maximum value?<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#What-happens-if-we-set-all-the-values-representing-the-blue-channel-to-the-maximum-value?" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px; text-align: left;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[15]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px; text-align: left;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Run this cell to set all blue channel values to 255</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># We first make a copy to avoid modifying the original image</span>
<span class="n" style="box-sizing: border-box;">im2</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">copy</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">im</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">im2</span><span class="p" style="box-sizing: border-box;">[:,:,</span><span class="mi" style="box-sizing: border-box; color: #666666;">2</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="mi" style="box-sizing: border-box; color: #666666;">255</span>
<span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">im2</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[15]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.image.AxesImage at 0x7f08e23d0ac8>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; text-align: left;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_06_python_solutions_32_1.png" src="https://training.digitalearthafrica.org/en/latest/_images/python_basics_06_python_solutions_32_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px;" /></div>
</div>
<p id="What-happens-if-we-set-all-the-values-representing-the-blue-channel-to-the-maximum-value?" style="box-sizing: border-box; text-align: left;">The index notation <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">[:,:,2]</span></code> is selecting pixels at all heights and all widths, but only the 3rd colour channel.</p>
<section id="Can-you-modify-the-above-code-cell-to-set-all-red-values-to-the-maximum-value-of-255?" style="box-sizing: border-box; color: #000000; font-family: Arial, sans-serif;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699; text-align: left;">3.4 Can you modify the above code cell to set all red values to the maximum value of <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">255</span></code>?<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#Can-you-modify-the-above-code-cell-to-set-all-red-values-to-the-maximum-value-of-255?" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px; text-align: left;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[16]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px; text-align: left;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">im2</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">copy</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">im</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">im2</span><span class="p" style="box-sizing: border-box;">[:,:,</span><span class="mi" style="box-sizing: border-box; color: #666666;">0</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="mi" style="box-sizing: border-box; color: #666666;">255</span>
<span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">im2</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[16]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.image.AxesImage at 0x7f08e0b34ef0>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none; text-align: left;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_06_python_solutions_35_1.png" src="https://training.digitalearthafrica.org/en/latest/_images/python_basics_06_python_solutions_35_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px; float: left;" /></div>
</div>
</section>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@87bf5080127e470c81dfc283685514b8" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@97abbc31b08a4fe094e01332b94e9dec">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@97abbc31b08a4fe094e01332b94e9dec" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px; text-align: left;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;">[17]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px; text-align: left;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="o" style="box-sizing: border-box; color: #666666;">%</span><span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">matplotlib</span> inline
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">numpy</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">np</span>
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">from</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">matplotlib</span> <span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">pyplot</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="n" style="box-sizing: border-box;">plt</span>
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">from</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">matplotlib</span> <span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">colors</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># grass = 1</span>
<span class="n" style="box-sizing: border-box;">area</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">ones</span><span class="p" style="box-sizing: border-box;">((</span><span class="mi" style="box-sizing: border-box; color: #666666;">100</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">100</span><span class="p" style="box-sizing: border-box;">))</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># crops = 2</span>
<span class="n" style="box-sizing: border-box;">area</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">10</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">60</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">20</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">50</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="mi" style="box-sizing: border-box; color: #666666;">2</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># city = 3</span>
<span class="n" style="box-sizing: border-box;">area</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">70</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">90</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">60</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">80</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="mi" style="box-sizing: border-box; color: #666666;">3</span>
<span class="n" style="box-sizing: border-box;">index</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="p" style="box-sizing: border-box;">{</span><span class="mi" style="box-sizing: border-box; color: #666666;">1</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'green'</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">2</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'yellow'</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">3</span><span class="p" style="box-sizing: border-box;">:</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'grey'</span><span class="p" style="box-sizing: border-box;">}</span>
<span class="n" style="box-sizing: border-box;">cmap</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">colors</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">ListedColormap</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">index</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">values</span><span class="p" style="box-sizing: border-box;">())</span>
</pre>
</div>
</div>
</div>
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699; text-align: left;">4.1 The harvesting season has arrived and our cropping lands have changed colour to brown. Can you:<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#4.1-The-harvesting-season-has-arrived-and-our-cropping-lands-have-changed-colour-to-brown.-Can-you:" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<section id="4.1.1-Modify-the-yellow-area-to-contain-the-new-value-4?" style="box-sizing: border-box;">
<h4 style="box-sizing: border-box; font-size: 18.4px; color: #336699;">4.1.1 Modify the yellow area to contain the new value <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 13.8px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">4</span></code>?<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#4.1.1-Modify-the-yellow-area-to-contain-the-new-value-4?" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h4>
</section>
<section id="4.1.2-Add-a-new-entry-to-the-index-dictionary-mapping-number-4-to-the-value-brown." style="box-sizing: border-box;">
<h4 style="box-sizing: border-box; font-size: 18.4px; color: #336699;">4.1.2 Add a new entry to the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 13.8px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">index</span></code> dictionary mapping number <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 13.8px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">4</span></code> to the value <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 13.8px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">brown</span></code>.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#4.1.2-Add-a-new-entry-to-the-index-dictionary-mapping-number-4-to-the-value-brown." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h4>
</section>
<h4 style="box-sizing: border-box; font-size: 18.4px; color: #336699; text-align: left;">4.1.3 Plot the area.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#4.1.3-Plot-the-area." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h4>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[18]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># 4.1.1 Modify the yellow area to hold the value 4</span>
<span class="n" style="box-sizing: border-box;">area</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">10</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">60</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">20</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">50</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="mi" style="box-sizing: border-box; color: #666666;">4</span>
</pre>
</div>
</div>
</div>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[19]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># 4.1.2 Add a new key-value pair to index that maps 4 to 'brown'</span>
<span class="n" style="box-sizing: border-box;">index</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">4</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="s1" style="box-sizing: border-box; color: #ba2121;">'brown'</span>
</pre>
</div>
</div>
</div>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 0px; width: 696.469px; padding-top: 5px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[20]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># 4.1.3 Copy the cmap definition and re-run it to add the new colour</span>
<span class="n" style="box-sizing: border-box;">cmap</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">colors</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">ListedColormap</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">index</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">values</span><span class="p" style="box-sizing: border-box;">())</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Plot the area</span>
<span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">area</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">cmap</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="n" style="box-sizing: border-box;">cmap</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[20]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.image.AxesImage at 0x7f08e0b26198>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; text-align: left;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_06_python_solutions_41_1.png" src="https://training.digitalearthafrica.org/en/latest/_images/python_basics_06_python_solutions_41_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px;" /></div>
</div>
<p style="text-align: left;"><strong style="box-sizing: border-box;">Hint:</strong> If you want to plot the new area, you have to redefine <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">cmap</span></code> so the new value is assigned a colour in the colour map. Copy and paste the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">cmap</span> <span class="pre" style="box-sizing: border-box;">=</span> <span class="pre" style="box-sizing: border-box;">...</span></code> line from the original plot.</p>
<section id="4.2-Set-area[20:40,-80:95]-=-np.nan.-Plot-the-area-now." style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">4.2 Set <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">area[20:40,</span> <span class="pre" style="box-sizing: border-box;">80:95]</span> <span class="pre" style="box-sizing: border-box;">=</span> <span class="pre" style="box-sizing: border-box;">np.nan</span></code>. Plot the area now.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#4.2-Set-area[20:40,-80:95]-=-np.nan.-Plot-the-area-now." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[21]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Set the nan area</span>
<span class="n" style="box-sizing: border-box;">area</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">20</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">40</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">80</span><span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">95</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">nan</span>
</pre>
</div>
</div>
</div>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[22]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Plot the entire area</span>
<span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">area</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">cmap</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="n" style="box-sizing: border-box;">cmap</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[22]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.image.AxesImage at 0x7f08e0a78e48>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_06_python_solutions_45_1.png" src="https://training.digitalearthafrica.org/en/latest/_images/python_basics_06_python_solutions_45_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px;" /></div>
</div>
</section>
<section id="4.3-Find-the-median-of-the-area-array-from-4.2-using-np.nanmedian.-Does-this-match-your-visual-interpretation?-How-does-this-compare-to-using-np.median?" style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699; text-align: left;">4.3 Find the median of the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">area</span></code> array from 4.2 using <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">np.nanmedian</span></code>. Does this match your visual interpretation? How does this compare to using <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">np.median</span></code>?<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#4.3-Find-the-median-of-the-area-array-from-4.2-using-np.nanmedian.-Does-this-match-your-visual-interpretation?-How-does-this-compare-to-using-np.median?" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[23]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Use np.nanmedian to find the median of the area</span>
<span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">nanmedian</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">area</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[23]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">1.0
</pre>
</div>
</div>
</div>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 0px; width: 696.469px; padding-top: 5px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[24]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">median</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">area</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[24]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">nan
</pre>
</div>
</div>
</div>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">np.median</span></code> returns a value of <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">nan</span></code> because it cannot interpret no-data pixels. <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">np.nanmedian</span></code> excludes NaN values, so it returns a value of <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">1</span></code> which indicates grass. This matches the plot of <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">area</span></code>.</p>
</section>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@vertical+block@c9f09ef16cfa4fefadd39fe0c04391cf" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@6c63610f5d0a4f6da8a0266ebe282abe">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101+2021+type@html+block@6c63610f5d0a4f6da8a0266ebe282abe" data-request-token="f7612520881a11efa85e837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<p></p>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[25]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="o" style="box-sizing: border-box; color: #666666;">%</span><span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">matplotlib</span> inline
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">numpy</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">np</span>
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">from</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">matplotlib</span> <span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">pyplot</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="n" style="box-sizing: border-box;">plt</span>
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">xarray</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">xr</span>
<span class="n" style="box-sizing: border-box;">guinea_bissau</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">xr</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">open_dataset</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #ba2121;">'guinea_bissau.nc'</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<section id="5.1-Can-you-access-to-the-crs-value-in-the-attributes-of-the-guinea_bissau-xarray.Dataset?" style="box-sizing: border-box; color: #000000;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">5.1 Can you access to the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">crs</span></code> value in the attributes of the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">guinea_bissau</span></code> <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">xarray.Dataset</span></code>?<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#5.1-Can-you-access-to-the-crs-value-in-the-attributes-of-the-guinea_bissau-xarray.Dataset?" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<blockquote style="box-sizing: border-box; margin: 0px 0px 24px 24px; line-height: 24px;">
<div style="box-sizing: border-box;">
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><strong style="box-sizing: border-box;">Hint:</strong> You can call upon <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">attributes</span></code> in the same way you would select a <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">variable</span></code> or <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">coordinate</span></code>.</p>
</div>
</blockquote>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[26]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Replace the ? with the attribute name</span>
<span class="n" style="box-sizing: border-box;">guinea_bissau</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">crs</span>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[26]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">'EPSG:32628'
</pre>
</div>
</div>
</div>
</section>
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">5.2 Select the region of the <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">blue</span></code> variable delimited by these coordinates:<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#5.2-Select-the-region-of-the-blue-variable-delimited-by-these-coordinates:" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<p style="box-sizing: border-box; color: #000000; padding-left: 30px; text-align: left;"><span style="color: #3c3c3c;">latitude of range [1335000, 1329030]</span></p>
<p style="box-sizing: border-box; color: #000000; padding-left: 30px; text-align: left;"><span style="color: #3c3c3c;">longitude of range [389520, 395490]</span></p>
<blockquote style="box-sizing: border-box; margin: 0px 0px 24px 24px; line-height: 24px;">
<div style="box-sizing: border-box;">
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><strong style="box-sizing: border-box;">Hint:</strong> Do we want to use <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">sel()</span></code> or <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">isel()</span></code>? Which coordinate is <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">x</span></code> and which is <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">y</span></code>?</p>
</div>
</blockquote>
<section id="5.3-Plot-the-selected-region-using-imshow,-then-plot-the-region-using-.plot()." style="box-sizing: border-box; color: #000000; font-family: Arial, sans-serif;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">5.3 Plot the selected region using <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">imshow</span></code>, then plot the region using <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">.plot()</span></code>.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#5.3-Plot-the-selected-region-using-imshow,-then-plot-the-region-using-.plot()." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[27]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Plot using plt.imshow</span>
<span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">guinea_bissau</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">blue</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">sel</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">x</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="nb" style="box-sizing: border-box; color: #008000;">slice</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">389520</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">395490</span><span class="p" style="box-sizing: border-box;">),</span> <span class="n" style="box-sizing: border-box;">y</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="nb" style="box-sizing: border-box; color: #008000;">slice</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">1335000</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">1329030</span><span class="p" style="box-sizing: border-box;">)))</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[27]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.image.AxesImage at 0x7f08cb8f0da0>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_06_python_solutions_58_1.png" src="https://training.digitalearthafrica.org/en/latest/_images/python_basics_06_python_solutions_58_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px;" /></div>
</div>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[28]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Plot using .plot()</span>
<span class="n" style="box-sizing: border-box;">guinea_bissau</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">blue</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">sel</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">x</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="nb" style="box-sizing: border-box; color: #008000;">slice</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">389520</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">395490</span><span class="p" style="box-sizing: border-box;">),</span> <span class="n" style="box-sizing: border-box;">y</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="nb" style="box-sizing: border-box; color: #008000;">slice</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">1335000</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">1329030</span><span class="p" style="box-sizing: border-box;">))</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">plot</span><span class="p" style="box-sizing: border-box;">()</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[28]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.collections.QuadMesh at 0x7f08cb824898>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_06_python_solutions_59_1.png" src="https://training.digitalearthafrica.org/en/latest/_images/python_basics_06_python_solutions_59_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px;" /></div>
</div>
</section>
<section id="Can-you-change-the-colour-map-to-'Blues'?" style="box-sizing: border-box; color: #000000; font-family: Arial, sans-serif;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">5.4 Can you change the colour map to <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">'Blues'</span></code>?<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/06_python_solutions.html#Can-you-change-the-colour-map-to-'Blues'?" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[29]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">guinea_bissau</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">blue</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">sel</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">x</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="nb" style="box-sizing: border-box; color: #008000;">slice</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">389520</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">395490</span><span class="p" style="box-sizing: border-box;">),</span> <span class="n" style="box-sizing: border-box;">y</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="nb" style="box-sizing: border-box; color: #008000;">slice</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">1335000</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">1329030</span><span class="p" style="box-sizing: border-box;">)),</span> <span class="n" style="box-sizing: border-box;">cmap</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="s1" style="box-sizing: border-box; color: #ba2121;">'Blues'</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[29]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.image.AxesImage at 0x7f08cb763eb8>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_06_python_solutions_61_1.png" src="https://training.digitalearthafrica.org/en/latest/_images/python_basics_06_python_solutions_61_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px;" /></div>
</div>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: -19px 0px 0px; width: 696.469px; padding-top: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[30]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">guinea_bissau</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">blue</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">sel</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">x</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="nb" style="box-sizing: border-box; color: #008000;">slice</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">389520</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">395490</span><span class="p" style="box-sizing: border-box;">),</span> <span class="n" style="box-sizing: border-box;">y</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="nb" style="box-sizing: border-box; color: #008000;">slice</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">1335000</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: #666666;">1329030</span><span class="p" style="box-sizing: border-box;">))</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">plot</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">cmap</span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span class="s1" style="box-sizing: border-box; color: #ba2121;">'Blues'</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[30]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.collections.QuadMesh at 0x7f08cb6d1710>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_06_python_solutions_62_1.png" src="https://training.digitalearthafrica.org/en/latest/_images/python_basics_06_python_solutions_62_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px;" /></div>
</div>
</section>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>