Commit ce593a5a authored by Trevor Bekolay's avatar Trevor Bekolay
Browse files

Added jwblin's changes to 01-numpy.ipynb

Generated .mds are identical to before (save for some whitespace).
parent d89353a0
......@@ -194,7 +194,9 @@
"we need to [assign](../../gloss.html#assignment) the array to a [variable](../../gloss.html#variable).\n",
"A variable is just a name for a value,\n",
"such as `x`, `current_temperature`, or `subject_id`. Python's variables must begin with a letter.\n",
"We can create a new variable simply by assigning a value to it using `=`:"
"We can create a new variable simply by assigning a value to it using `=`. As an illustration, let's\n",
"step back and instead of considering a table of data, consider the simplest \"collection\" of data, a single\n",
"value. The line below assigns a value to a variable:"
]
},
{
......@@ -411,8 +413,8 @@
"it isn't automatically updated when `weight_kg` changes.\n",
"This is different from the way spreadsheets work.\n",
"\n",
"Now that we know how to assign things to variables,\n",
"let's re-run `numpy.loadtxt` and save its result:"
"Just as we can assign a single value to a variable, we can also assign an array of values\n",
"to a variable using the same syntax. Let's re-run `numpy.loadtxt` and save its result:"
]
},
{
......@@ -784,7 +786,7 @@
]
}
],
"prompt_number": 18
"prompt_number": 17
},
{
"cell_type": "markdown",
......@@ -793,6 +795,54 @@
},
"source": [
"Arrays also know how to perform common mathematical operations on their values.\n",
"The simplest operations with data are arithmetic: add, subtract, multiply, \n",
"and divide. When you do such operations on arrays, the operation is done on each\n",
"individual element of the array. Thus:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"doubledata = data * 2.0"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 18
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"will create a new array `doubledata` whose elements have the value of two times\n",
"the value of the *corresponding* elements in `data`. If, instead of taking an array\n",
"and doing arithmetic with a single value (as above) you did the arithmetic operation\n",
"with another array of the same size and shape, the operation will be done on\n",
"*corresponding* elements of the two arrays. Thus:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"doubledata = data * 2.0\n",
"tripledata = doubledata + data"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 19
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"will give you an array where `tripledata[0,0]` will equal `doubledata[0,0]` plus `data[0,0]`,\n",
"and so on for all other elements of the arrays.\n",
"\n",
"Often, we want to do more than add, subtract, multiply, and divide values of data.\n",
"Arrays also know how to do more complex operations on their values.\n",
"If we want to find the average inflammation for all patients on all days,\n",
"for example,\n",
"we can just ask the array for its mean value"
......@@ -817,7 +867,7 @@
]
}
],
"prompt_number": 19
"prompt_number": 20
},
{
"cell_type": "markdown",
......@@ -865,7 +915,7 @@
]
}
],
"prompt_number": 20
"prompt_number": 21
},
{
"cell_type": "markdown",
......@@ -902,7 +952,7 @@
]
}
],
"prompt_number": 21
"prompt_number": 22
},
{
"cell_type": "markdown",
......@@ -933,7 +983,7 @@
]
}
],
"prompt_number": 22
"prompt_number": 23
},
{
"cell_type": "markdown",
......@@ -994,7 +1044,7 @@
]
}
],
"prompt_number": 23
"prompt_number": 24
},
{
"cell_type": "markdown",
......@@ -1025,7 +1075,7 @@
]
}
],
"prompt_number": 24
"prompt_number": 25
},
{
"cell_type": "markdown",
......@@ -1062,7 +1112,7 @@
]
}
],
"prompt_number": 25
"prompt_number": 26
},
{
"cell_type": "markdown",
......@@ -1111,7 +1161,7 @@
]
}
],
"prompt_number": 26
"prompt_number": 27
},
{
"cell_type": "markdown",
......@@ -1174,7 +1224,7 @@
"cell_tags": []
},
"outputs": [],
"prompt_number": 27
"prompt_number": 28
},
{
"cell_type": "markdown",
......@@ -1211,7 +1261,7 @@
]
}
],
"prompt_number": 28
"prompt_number": 29
},
{
"cell_type": "markdown",
......@@ -1247,7 +1297,7 @@
]
}
],
"prompt_number": 29
"prompt_number": 30
},
{
"cell_type": "markdown",
......@@ -1313,7 +1363,7 @@
]
}
],
"prompt_number": 30
"prompt_number": 31
},
{
"cell_type": "markdown",
......@@ -1405,7 +1455,7 @@
]
}
],
"prompt_number": 31
"prompt_number": 32
},
{
"cell_type": "markdown",
......
......@@ -365,17 +365,21 @@ The simplest operations with data are arithmetic: add, subtract, multiply,
and divide. When you do such operations on arrays, the operation is done on each
individual element of the array. Thus:
<pre class="in"><code>doubledata = data * 2.0</code></pre>
will create a new array `doubledata` whose elements have the value of two times
the value of the *corresponding* elements in `data`. If, instead of taking an array
and doing arithmetic with a single value (as above) you did the arithmetic operation
with another array of the same size and shape, the operation will be done on
*corresponding* elements of the two arrays. Thus:
<pre class="in"><code>doubledata = data * 2.0
tripledata = doubledata + data</code></pre>
will give you an array where `tripledata[0,0]` will equal `doubledata[0,0]` plus `data[0,0]`,
and so on for all other elements of the arrays.
......
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