<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@ae3fa299111e4150821ee8724480817e" data-request-token="080a0d40881311efa85e837f534d2eba" 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@84bd131adaa84e7c862948f396daf1c3">
<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@84bd131adaa84e7c862948f396daf1c3" data-request-token="080a0d40881311efa85e837f534d2eba" 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 tutorial introduces numpy (pronounced num-pye, rhymes with eye), a Python library for performing numerical computations in Python. We will learn how to create and manipulate numpy arrays, which are useful matrix-like structures for holding large amounts of data.</p>
<section id="Download-the-tutorial-notebook" style="box-sizing: border-box; color: #000000;">
<h2 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 24px; color: #336699; text-align: left;">Download the tutorial notebook</h2>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><a class="reference external" href="/assets/courseware/v1/9c4888117a4e8e76d695e59d2a14bcf5/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block/02_download-numpy.ipynb" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer;" target="[object Object]">Download the Python basics 2 tutorial notebook</a></p>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;">To view this notebook on the Sandbox, you will need to first download it to your computer, then upload it to the Sandbox. Ensure you have followed the set-up prerequisities listed in <a class="reference internal" href="/courses/course-v1:digitalearthafrica+DEA101+2021/jump_to_id/9c210d02e6fe484a8ce67c67a1e9c2fa" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer;" target="[object Object]">Python basics 1: Jupyter</a>, and then follow these instructions:</p>
<ol class="arabic simple" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 24px; padding-left: 0px; list-style-position: initial; list-style-image: initial; line-height: 24px; text-align: left;">
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">Download the notebook by clicking the link above.</p>
</li>
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">On the Sandbox, open the <strong style="box-sizing: border-box;">Training</strong> folder.</p>
</li>
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">Click the <strong style="box-sizing: border-box;">Upload Files</strong> button as shown below.</p>
</li>
</ol>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><img alt="Upload button." class="no-scaled-link" src="https://learn.digitalearthafrica.org/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block@05_solution_uploadbutton.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; width: 400px;" /></p>
<ol class="arabic simple" start="4" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 24px; padding-left: 0px; list-style-position: initial; list-style-image: initial; line-height: 24px; text-align: left;">
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">Select the downloaded notebook using the file browser. Click <strong style="box-sizing: border-box;">OK</strong>.</p>
</li>
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">The solution notebook will appear in the <strong style="box-sizing: border-box;">Training</strong> folder. Double-click to open it.</p>
</li>
</ol>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;">You can now use the tutorial notebook as an interactive version of this webpage.</p>
<div class="admonition note" style="box-sizing: border-box; -webkit-font-smoothing: antialiased; padding: 12px; line-height: 24px; margin-bottom: 24px; background: #e7f2fa;">
<p class="admonition-title" style="box-sizing: border-box; line-height: 1; margin: -12px -12px 12px; font-size: inherit; font-family: inherit; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: bold; font-stretch: normal; text-rendering: auto; -webkit-font-smoothing: antialiased; color: #ffffff; background: #6ab0de; padding: 6px 12px; text-align: left;">Note</p>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px; text-align: left;">The tutorial notebook should look like the text and code below. However, the tutorial notebook outputs are blank (i.e. no results showing after code cells). Follow the instructions in the notebook to run the cells in the tutorial notebook. Refer to this page to check your outputs look similar.</p>
</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@c8f6c4226901419cb10458aa0a3416b7" data-request-token="080a0d40881311efa85e837f534d2eba" 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@c5afd40f2e254c9580a9d2c6a472c1f1">
<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@c5afd40f2e254c9580a9d2c6a472c1f1" data-request-token="080a0d40881311efa85e837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<h3>Import numpy</h3>
<p style="text-align: left;">In order to be able to use numpy we need to import the numpy library using the special word <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;">import</span></code>. To avoid typing <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;">numpy</span></code> every time we want to use one of its functions, we can provide an alias using the special word <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;">as</span></code>. We will nickname numpy as <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</span></code>:</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; 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; 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;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; 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: 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>
<div style="box-sizing: border-box; text-align: left;"><strong style="box-sizing: border-box;">Note:</strong> If we do not <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;">import</span> <span class="pre" style="box-sizing: border-box;">numpy</span></code>, we cannot use any of the numpy functions. If you forget to import packages, you may get an error that says <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;">name</span> <span class="pre" style="box-sizing: border-box;">is</span> <span class="pre" style="box-sizing: border-box;">not</span> <span class="pre" style="box-sizing: border-box;">defined</span></code>.</div>
<p style="text-align: left;">Now, we have access to all the functions available in <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;">numpy</span></code> by typing <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.name_of_function</span></code>. For example, the equivalent 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> <span class="pre" style="box-sizing: border-box;">+</span> <span class="pre" style="box-sizing: border-box;">1</span></code> in Python can be done in <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;">numpy</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; color: #000000; font-family: Arial, sans-serif; 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>[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;">
<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;">add</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;">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; color: #000000; font-family: Arial, sans-serif; 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>[2]:
</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;">2
</pre>
</div>
</div>
</div>
<p style="text-align: left;">By default the result of a function or operation is shown underneath the cell containing the code. If we want to reuse this result for a later operation we can assign it to a variable. For instance, let us call the 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: 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>:</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; 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> <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;">add</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>
</pre>
</div>
</div>
</div>
<p style="text-align: left;">We have just declared a 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: 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> that holds the result of the function. We can now use of display this variable, at any point of this notebook. For example we can show its contents by typing the variable name in a new cell:</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; color: #000000; font-family: Arial, sans-serif; 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>[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="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; color: #000000; font-family: Arial, sans-serif; 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>[4]:
</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;">5
</pre>
</div>
</div>
</div>
<h3 style="text-align: left;">Numpy arrays</h3>
<p style="text-align: left;">One of numpy’s core concepts is 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;">array</span></code>. They can hold multi-dimensional data. To declare a numpy array explicity we do:</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; color: #000000; font-family: Arial, sans-serif; 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>[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="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;">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>
</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; color: #000000; font-family: Arial, sans-serif; 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>[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;">array([1, 2, 3, 4, 5, 6, 7, 8, 9])
</pre>
</div>
</div>
</div>
<div style="box-sizing: border-box; text-align: left;"><strong style="box-sizing: border-box;">Note:</strong> The array defined above has only 1 dimension.</div>
<p style="text-align: left;">Most of the functions and operations defined in numpy can be applied to arrays. For example, with the previous <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;">add</span></code> operation:</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; color: #000000;">
<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="n" style="box-sizing: border-box;">arr1</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;">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="n" style="box-sizing: border-box;">arr2</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;">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="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="n" style="box-sizing: border-box;">arr1</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">arr2</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; 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: 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([ 4, 6, 8, 10])
</pre>
</div>
</div>
</div>
<p style="text-align: left;">We can also add arrays using the following convenient notation:</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; 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>[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;">arr1</span> <span class="o" style="box-sizing: border-box; color: #666666;">+</span> <span class="n" style="box-sizing: border-box;">arr2</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; 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: 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([ 4, 6, 8, 10])
</pre>
</div>
</div>
</div>
<p style="text-align: left;">Arrays can be sliced and diced. We can get subsets of the arrays using the indexing notation 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;">[</span> <span class="pre" style="box-sizing: border-box;">start</span> <span class="pre" style="box-sizing: border-box;">:</span> <span class="pre" style="box-sizing: border-box;">end</span> <span class="pre" style="box-sizing: border-box;">:</span> <span class="pre" style="box-sizing: border-box;">stride</span> <span class="pre" style="box-sizing: border-box;">]</span></code>. Let’s see what this means:</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; 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>[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="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="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr</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="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr</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="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr</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="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr</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>
</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; color: #000000; font-family: Arial, sans-serif;">
<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;">
<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;">5
[ 5 6 7 8 9 10 11 12 13 14 15]
[0 1 2 3 4]
[ 0 2 4 6 8 10 12 14]
</pre>
</div>
</div>
</div>
<p style="text-align: left;">Experiment playing with the indexes to understand the meaning 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;">start</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: 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;">end</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: 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;">stride</span></code>. What happens if you don’t specify a start? What value does numpy use instead?</p>
<div style="box-sizing: border-box; text-align: left;">
<div style="box-sizing: border-box; text-align: left;"><strong style="box-sizing: border-box;">Note:</strong> Numpy indexes start on <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</span></code>, the same convention used in Python lists.</div>
<div style="box-sizing: border-box; text-align: left;"></div>
<p style="text-align: left;">Indexes can also be negative, meaning that you start counting by the end. For example, to select the last 2 elements in an array we can do:</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; color: #000000; font-family: Arial, sans-serif; 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>[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;">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="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;">2</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; color: #000000; font-family: Arial, sans-serif; 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>[9]:
</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([14, 15])
</pre>
</div>
</div>
</div>
<p style="text-align: left;">Numpy arrays can have multiple dimensions. Dimensions are indicated using nested square brackets <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;">[</span> <span class="pre" style="box-sizing: border-box;">]</span></code>. The convention in numpy is that the outer <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;">[</span> <span class="pre" style="box-sizing: border-box;">]</span></code> represent the first dimension and the innermost <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;">[</span> <span class="pre" style="box-sizing: border-box;">]</span></code> contains the last dimension.</p>
<p><img src="https://learn.digitalearthafrica.org/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block@numpy_array_t.png" alt="drawing" /></p>
<p></p>
<p style="text-align: left;">The following cell declares a 2-dimensional array with shape (1, 9).</p>
<div style="box-sizing: border-box;">
<p style="text-align: left;"><strong>Tip</strong>: Notice the nested (double) square brackets [[ ]]. As there are two brackets, this indicates the array is 2-dimensional.</p>
<div style="box-sizing: border-box;">
<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>[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;">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;">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>
</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>[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([[1, 2, 3, 4, 5, 6, 7, 8, 9]])</pre>
</div>
</div>
</div>
<p style="text-align: left;">To visualise the shape (dimensions) of a numpy array we can add the suffix <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;">.shape</span></code> to an array expression or variable containing a numpy array.</p>
<div style="box-sizing: border-box;">
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px; color: #000000; font-family: Arial, sans-serif; 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>[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="n" style="box-sizing: border-box;">arr1</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;">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="n" style="box-sizing: border-box;">arr2</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;">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="n" style="box-sizing: border-box;">arr3</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;">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="n" style="box-sizing: border-box;">arr1</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">shape</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">arr2</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">shape</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">arr3</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">shape</span><span class="p" 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;">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;">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="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">shape</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; color: #000000; font-family: Arial, sans-serif; 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; 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>[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; 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;">((9,), (1, 9), (9, 1), (3,))<br />
</pre>
</div>
</div>
</div>
<p style="text-align: left;"></p>
</div>
</div>
</div>
<section id="Exercises" style="box-sizing: border-box;">
<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; color: #000000; font-family: Arial, sans-serif;"></section>
</section>
</div>
</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@69a922e349544c15a9a8e5853e142630" data-request-token="080a0d40881311efa85e837f534d2eba" 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@cbcd76dd3d094900ae9a151b39617b29">
<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@cbcd76dd3d094900ae9a151b39617b29" data-request-token="080a0d40881311efa85e837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<div style="box-sizing: border-box;">
<div style="box-sizing: border-box;">
<div style="box-sizing: border-box;">
<p>Numpy arrays can contain numerical values of different types. These types can be divided in these groups:</p>
<p style="box-sizing: border-box;"><strong><span style="color: #000000;">Integers</span></strong></p>
<ul>
<li><strong><span style="font-family: Arial, sans-serif;">Unsigned</span></strong></li>
<ul>
<li>8 bits: <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></li>
<li>16 bits: <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;">uint16</span></code></li>
<li>32 bits: <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;">uint32</span></code></li>
<li>64 bits: <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;">uint64</span></code></li>
</ul>
<li><strong>Signed</strong></li>
<ul>
<li>8 bits: <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;">int8</span></code></li>
<li>16 bits: <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;">int16</span></code></li>
<li>32 bits: <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;">int32</span></code></li>
<li>64 bits: <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;">int64</span></code></li>
</ul>
</ul>
<strong><span style="color: #000000;">Floats</span></strong><br />
<ul>
<li>32 bits: <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;">float32</span></code></li>
<li>64 bits: <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;">float64</span></code></li>
</ul>
<p>We can look up the type of an array by using 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;">.dtype</span></code> suffix.</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; 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>[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="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;">ones</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;">10</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="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;">dtype</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; 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: 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>[12]:
</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;">dtype('float64')</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<p></p>
<h3>Boolean (true/false) data</h3>
<p>Numpy arrays normally store numeric values but they can also contain boolean 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: 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;">'bool'</span></code>. Boolean is a data type that can have two possible 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: 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;">True</span></code><span style="color: #000000; font-family: Arial, sans-serif;">, or </span><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;">False</span></code>. For example:</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; 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>[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="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="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">True</span><span class="p" style="box-sizing: border-box;">,</span> <span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">False</span><span class="p" style="box-sizing: border-box;">,</span> <span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">True</span><span class="p" style="box-sizing: border-box;">])</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;">arr</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">shape</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="n" style="box-sizing: border-box;">dtype</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; 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: 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;">(array([ True, False, True]), (3,), dtype('bool'))
</pre>
</div>
</div>
</div>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px;">We can operate with boolean arrays using the numpy functions for performing logical operations such as <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;">and</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: 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;">or</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; 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>[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;">
<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;">arr1</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="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">True</span><span class="p" style="box-sizing: border-box;">,</span> <span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">True</span><span class="p" style="box-sizing: border-box;">,</span> <span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">False</span><span class="p" style="box-sizing: border-box;">,</span> <span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">False</span><span class="p" style="box-sizing: border-box;">])</span>
<span class="n" style="box-sizing: border-box;">arr2</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="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">True</span><span class="p" style="box-sizing: border-box;">,</span> <span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">False</span><span class="p" style="box-sizing: border-box;">,</span> <span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">True</span><span class="p" style="box-sizing: border-box;">,</span> <span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">False</span><span class="p" style="box-sizing: border-box;">])</span>
<span class="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" 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;">logical_and</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr1</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">arr2</span><span class="p" style="box-sizing: border-box;">))</span>
<span class="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" 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;">logical_or</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr1</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">arr2</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; color: #000000; font-family: Arial, sans-serif;">
<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;">
<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;">[ True False False False]
[ True True True False]
</pre>
</div>
</div>
</div>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px;">These operations are conveniently offered by numpy with the symbols <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;">*</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: 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;">and</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: 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;">+</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: 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;">or</span></code>).</p>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px;"><strong style="box-sizing: border-box;">Note:</strong> Here 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;">*</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: 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;">+</span></code> symbols are not performing multiplication and addition as with numerical arrays. Numpy detects the type of the arrays involved in the operation and changes the behaviour of these operators.</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; 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>[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;">
<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="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr1</span> <span class="o" style="box-sizing: border-box; color: #666666;">*</span> <span class="n" style="box-sizing: border-box;">arr2</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr1</span> <span class="o" style="box-sizing: border-box; color: #666666;">+</span> <span class="n" style="box-sizing: border-box;">arr2</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; color: #000000; font-family: Arial, sans-serif;">
<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;">
<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;">[ True False False False]
[ True True True False]
</pre>
</div>
</div>
</div>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px;">Boolean arrays are often the result of comparing a numerical arrays with certain values. This is sometimes useful to detect values that are equal, below or above a number in a numpy array. For example, if we want to know which values in an array are equal to 1, and the values that are greater than 2 we can do:</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; 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>[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;">
<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="nb" style="box-sizing: border-box; color: #008000;">print</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;">1</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="nb" style="box-sizing: border-box; color: #008000;">print</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;">2</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; color: #000000; font-family: Arial, sans-serif;">
<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;">
<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;">[ True False False True False False True False False True]
[False True True False True True False True True False]
</pre>
</div>
</div>
</div>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px;">You can use a boolean array to mask out <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;">False</span></code> values from a numeric array. The returned array only contains the numeric values which are at the same index as <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;">True</span></code> values in 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;">mask</span></code> array.</p>
<p></p>
<section id="Introduction-to-numpy" style="box-sizing: border-box; color: #000000; font-family: Arial, sans-serif;">
<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>[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;">
<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;">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="n" style="box-sizing: border-box;">mask</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="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">True</span><span class="p" style="box-sizing: border-box;">,</span><span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">False</span><span class="p" style="box-sizing: border-box;">,</span><span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">True</span><span class="p" style="box-sizing: border-box;">,</span><span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">False</span><span class="p" style="box-sizing: border-box;">,</span><span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">True</span><span class="p" style="box-sizing: border-box;">,</span><span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">False</span><span class="p" style="box-sizing: border-box;">,</span><span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">True</span><span class="p" style="box-sizing: border-box;">,</span><span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">False</span><span class="p" style="box-sizing: border-box;">,</span><span class="kc" style="box-sizing: border-box; color: #008000; font-weight: bold;">True</span><span class="p" style="box-sizing: border-box;">])</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;">mask</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>[17]:
</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([1, 3, 5, 7, 9])</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@dce599ba11324e78a1430ed52efe73c8" data-request-token="080a0d40881311efa85e837f534d2eba" 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@b1f8326a4253458591080e5a364308a1">
<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@b1f8326a4253458591080e5a364308a1" data-request-token="080a0d40881311efa85e837f534d2eba" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<section id="Exercises" style="box-sizing: border-box;">
<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; text-align: left;">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/02_numpy.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 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: 16px; 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>[ ]:
</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: 16px; 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 function to add 34 and 29</span>
</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/02_numpy.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 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: 16px; 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>[ ]:
</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: 16px; 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># Substitute the ? symbols by the correct expressions and values
# Declare the array
arr = ?
# Slice array for the last 3 items only
arr[?:?]
</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/02_numpy.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 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: 16px; 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>[ ]:
</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: 16px; 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>arr = np.array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
# Substitute the ? symbols by the correct expressions and values
arr[?]
</pre>
</div>
</div>
</div>
</section>
<section id="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." style="box-sizing: border-box;">
<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/02_numpy.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>
<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> 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>
<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: 16px; 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>[ ]:
</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: 16px; 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># Substitute the ? symbols by the correct expressions and values
arr[?:?:?]
</pre>
</div>
</div>
</div>
</section>
<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/02_numpy.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>
<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> If you are stuck, reread the section on boolean arrays.</p>
</div>
<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: 16px; 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>[ ]:
</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: 16px; 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="o" style="box-sizing: border-box; color: #666666;">?</span>
</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; text-align: left;">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/02_numpy.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>
<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> 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>
<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; 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: 16px; 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>[ ]:
</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; text-align: left;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; 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>
</pre>
</div>
</div>
</div>
</section>
</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@03822b563bd54fff91021149f8b3fe56" data-request-token="080a0d40881311efa85e837f534d2eba" 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@169c21686b924d46b8a332b7ee03f72f">
<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@169c21686b924d46b8a332b7ee03f72f" data-request-token="080a0d40881311efa85e837f534d2eba" 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;">Numpy is a fundamental numerical computing library in Python programming and it is useful to understand how it works. Next, we explore plotting geospatial data using matplotlib.</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>