Skip to content

Commit 14d2951

Browse files
committed
Regenerate HTML
1 parent 178ba28 commit 14d2951

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

01-numpy.html

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ <h2 id="learning-objectives"><span class="glyphicon glyphicon-certificate"></spa
3535
<div class="panel-body">
3636
<ul>
3737
<li>Explain what a library is, and what libraries are used for.</li>
38-
<li>Load a Python library and use the things it contains.</li>
38+
<li>Import a Python library and use the things it contains.</li>
3939
<li>Read tabular data from a file into a program.</li>
4040
<li>Assign values to variables.</li>
4141
<li>Select individual values and subsections from data.</li>
@@ -45,9 +45,9 @@ <h2 id="learning-objectives"><span class="glyphicon glyphicon-certificate"></spa
4545
</div>
4646
</section>
4747
<p>Words are useful, but what’s more useful are the sentences and stories we build with them. Similarly, while a lot of powerful, general tools are built into languages like Python, specialized tools built up from these basic units live in <a href="reference.html#library">libraries</a> that can be called upon when needed.</p>
48-
<p>In order to load our inflammation data, we need to <a href="reference.html#import">import</a> a library called <a href="http://docs.scipy.org/doc/numpy/" title="NumPy Documentation">NumPy</a>. In general you should use this library if you want to do fancy things with numbers, especially if you have matrices or arrays. We can load NumPy using:</p>
48+
<p>In order to load our inflammation data, we need to access (<a href="reference.html#import">import</a> in Python terminology) a library called <a href="http://docs.scipy.org/doc/numpy/" title="NumPy Documentation">NumPy</a>. In general you should use this library if you want to do fancy things with numbers, especially if you have matrices or arrays. We can import NumPy using:</p>
4949
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="im">import</span> numpy</code></pre></div>
50-
<p>Importing a library is like getting a piece of lab equipment out of a storage locker and setting it up on the bench. Libraries provide additional functionality to the basic Python package, much like a new piece of equipment adds functionality to a lab space. Once you’ve loaded the library, we can ask the library to read our data file for us:</p>
50+
<p>Importing a library is like getting a piece of lab equipment out of a storage locker and setting it up on the bench. Libraries provide additional functionality to the basic Python package, much like a new piece of equipment adds functionality to a lab space. Once you’ve imported the library, we can ask the library to read our data file for us:</p>
5151
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python">numpy.loadtxt(fname<span class="op">=</span><span class="st">&#39;inflammation-01.csv&#39;</span>, delimiter<span class="op">=</span><span class="st">&#39;,&#39;</span>)</code></pre></div>
5252
<pre class="output"><code>array([[ 0., 0., 1., ..., 3., 0., 0.],
5353
[ 0., 1., 2., ..., 1., 0., 1.],
@@ -122,7 +122,19 @@ <h2 id="whos-who-in-the-memory"><span class="glyphicon glyphicon-pushpin"></span
122122
<p>Now that our data is in memory, we can start doing things with it. First, let’s ask what <a href="reference.html#type">type</a> of thing <code>data</code> refers to:</p>
123123
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="bu">print</span>(<span class="bu">type</span>(data))</code></pre></div>
124124
<pre class="output"><code>&lt;class &#39;numpy.ndarray&#39;&gt;</code></pre>
125-
<p>The output tells us that <code>data</code> currently refers to an N-dimensional array created by the NumPy library. These data correspond to arthritis patients’ inflammation. The rows are the individual patients and the columns are their daily inflammation measurements. We can see what the array’s <a href="reference.html#shape">shape</a> is like this:</p>
125+
<p>The output tells us that <code>data</code> currently refers to an N-dimensional array created by the NumPy library. These data correspond to arthritis patients’ inflammation. The rows are the individual patients and the columns are their daily inflammation measurements.</p>
126+
<aside class="callout panel panel-info">
127+
<div class="panel-heading">
128+
<h2 id="data-type"><span class="glyphicon glyphicon-pushpin"></span>Data Type</h2>
129+
</div>
130+
<div class="panel-body">
131+
<p>A Numpy array contains one or more elements of the same type. <code>type</code> will only tell you that a variable is a NumPy array. We can also find the out the type of the data contained in the NumPy array.</p>
132+
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="bu">print</span>(data.dtype)</code></pre></div>
133+
<pre class="output"><code>dtype(&#39;float64&#39;)</code></pre>
134+
<p>This tells us that the NumPy array’s elements are <a href="reference.html#floating-point%20number">floating-point numbers</a>.</p>
135+
</div>
136+
</aside>
137+
<p>We can see what the array’s <a href="reference.html#shape">shape</a> is like this:</p>
126138
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="bu">print</span>(data.shape)</code></pre></div>
127139
<pre class="output"><code>(60, 40)</code></pre>
128140
<p>This tells us that <code>data</code> has 60 rows and 40 columns. When we created the variable <code>data</code> to store our arthritis data, we didn’t just create the array, we also created information about the array, called <a href="reference.html#member">members</a> or attributes. This extra information describes <code>data</code> in the same way an adjective describes a noun. <code>data.shape</code> is an attribute of <code>data</code> which describes the dimensions of <code>data</code>. We use the same dotted notation for the attributes of variables that we use for the functions in libraries because they have the same part-and-whole relationship.</p>

0 commit comments

Comments
 (0)