Commit 288981d5 authored by Greg Wilson's avatar Greg Wilson
Browse files

Updating .md files generated from notebooks

parent 5ea43302
......@@ -45,14 +45,13 @@ To do all that, we'll have to learn a little bit about programming.
Words are useful,
but what's more useful are the sentences and stories we use them to build.
but what's more useful are the sentences and stories we build with them.
Similarly,
while a lot of powerful tools are built into languages like Python,
even more lives in the [libraries](../../gloss.html#library) they are used to build.
even more live in the [libraries](../../gloss.html#library) they are used to build.
In order to load our inflammation data,
we need to [import](../../gloss.html#import) a library called NumPy
that knows how to operate on matrices:
we need to [import](../../gloss.html#import) a library called NumPy. In general you should use this library if you want to do fancy things with numbers, especially if you have matrices. We can load NumPy using:
<pre class="in"><code>import numpy</code></pre>
......@@ -78,7 +77,7 @@ we can ask the library to read our data file for us:
The expression `numpy.loadtxt(...)` is a [function call](../../gloss.html#function-call)
that asks Python to run the function `loadtxt` that belongs to the `numpy` library.
This [dotted notation](../../gloss.html#dotted-notation) is used everywhere in Python
to refer to the parts of things as `whole.part`.
to refer to the parts of things as `thing.component`.
`numpy.loadtxt` has two [parameters](../../gloss.html#parameter):
the name of the file we want to read,
......@@ -105,7 +104,7 @@ but didn't save the data in memory.
To do that,
we need to [assign](../../gloss.html#assignment) the array to a [variable](../../gloss.html#variable).
A variable is just a name for a value,
such as `x`, `current_temperature`, or `subject_id`.
such as `x`, `current_temperature`, or `subject_id`. Python's variables must begin with a letter.
We can create a new variable simply by assigning a value to it using `=`:
......@@ -299,7 +298,8 @@ the index is how many steps we have to take from the start to get the item we wa
> rather than the lower left.
> This is consistent with the way mathematicians draw matrices,
> but different from the Cartesian coordinates.
> The indices are (row, column) instead of (column, row) for the same reason.
> The indices are (row, column) instead of (column, row) for the same reason,
> which can be confusing when plotting data.
An index like `[30, 20]` selects a single element of an array,
......@@ -541,7 +541,7 @@ The mathematician Richard Hamming once said,
"The purpose of computing is insight, not numbers,"
and the best way to develop insight is often to visualize data.
Visualization deserves an entire lecture (or course) of its own,
but we can explore a few features of Python's `matplotlib` here.
but we can explore a few features of Python's `matplotlib` here. While there is no "official" plotting library, this package is the de facto standard.
First,
let's tell the IPython Notebook that we want our plots displayed inline,
rather than in a separate viewing window:
......
......@@ -146,6 +146,29 @@ though,
so if we want `5/9` to give us the right answer,
we have to write it as `5.0/9`, `5/9.0`, or some other variation.
Another way to create a floating-point answer is to explicitly tell the computer that you desire one. This is achieved by casting one of the numbers:
<pre class="in"><code>print &#39;float(10)/3 is:&#39;, float(10)/3</code></pre>
<div class="out"><pre class='out'><code>float(10)/3 is: 3.33333333333
</code></pre></div>
The advantage to this method is it can be used with existing variables. Let's take a look:
<pre class="in"><code>a = 10
b = 3
print &#39;a/b is:&#39;, a/b
print &#39;float(a)/b is:&#39;, float(a)/b</code></pre>
<div class="out"><pre class='out'><code>a/b is: 3
float(a)/b is: 3.33333333333
</code></pre></div>
See that was much easier than redefining `a` or `b`!
Let's fix our `fahr_to_kelvin` function with this new knowledge.
......
......@@ -239,16 +239,16 @@ that this bit is tricky.
and for each one,
give an example of input that will make that assertion fail.
~~~
def running(values):
assert len(values) > 0
result = [values[0]]
for v in values[1:]:
assert result[-1] >= 0
result.append(result[-1] + v)
assert result[-1] >= result[0]
return result
~~~
~~~python
def running(values):
assert len(values) > 0
result = [values[0]]
for v in values[1:]:
assert result[-1] >= 0
result.append(result[-1] + v)
assert result[-1] >= result[0]
return result
~~~
### Test-Driven Development
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment