Commit 7ab167b1 authored by Trevor Bekolay's avatar Trevor Bekolay
Browse files

Added some additional code to 01-numpy.ipynb

parent ce593a5a
{
"metadata": {
"name": "",
"signature": "sha256:7a4fe9c04bbdbc7c87c51585f2f9a499268e59a52aa3764c7e4bea5d40cda923"
"signature": "sha256:bdd5075bd4a75df8ed67c3124b0664471edfc1bfe6110ddcf01e68e156bcb9bb"
},
"nbformat": 3,
"nbformat_minor": 0,
......@@ -816,7 +816,43 @@
"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",
"the value of the *corresponding* elements in `data`."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print 'original:'\n",
"print data[:3, 36:]\n",
"print 'doubledata:'\n",
"print doubledata[:3, 36:]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"original:\n",
"[[ 2. 3. 0. 0.]\n",
" [ 1. 1. 0. 1.]\n",
" [ 2. 2. 1. 1.]]\n",
"doubledata:\n",
"[[ 4. 6. 0. 0.]\n",
" [ 2. 2. 0. 2.]\n",
" [ 4. 4. 2. 2.]]\n"
]
}
],
"prompt_number": 19
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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:"
......@@ -826,21 +862,48 @@
"cell_type": "code",
"collapsed": false,
"input": [
"doubledata = data * 2.0\n",
"tripledata = doubledata + data"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 19
"prompt_number": 20
},
{
"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",
"and so on for all other elements of the arrays."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print 'tripledata:'\n",
"print tripledata[:3, 36:]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"tripledata:\n",
"[[ 6. 9. 0. 0.]\n",
" [ 3. 3. 0. 3.]\n",
" [ 6. 6. 3. 3.]]\n"
]
}
],
"prompt_number": 21
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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",
......@@ -867,7 +930,7 @@
]
}
],
"prompt_number": 20
"prompt_number": 22
},
{
"cell_type": "markdown",
......@@ -915,7 +978,7 @@
]
}
],
"prompt_number": 21
"prompt_number": 23
},
{
"cell_type": "markdown",
......@@ -952,7 +1015,7 @@
]
}
],
"prompt_number": 22
"prompt_number": 24
},
{
"cell_type": "markdown",
......@@ -983,7 +1046,7 @@
]
}
],
"prompt_number": 23
"prompt_number": 25
},
{
"cell_type": "markdown",
......@@ -1044,7 +1107,7 @@
]
}
],
"prompt_number": 24
"prompt_number": 26
},
{
"cell_type": "markdown",
......@@ -1075,7 +1138,7 @@
]
}
],
"prompt_number": 25
"prompt_number": 27
},
{
"cell_type": "markdown",
......@@ -1112,7 +1175,7 @@
]
}
],
"prompt_number": 26
"prompt_number": 28
},
{
"cell_type": "markdown",
......@@ -1161,7 +1224,7 @@
]
}
],
"prompt_number": 27
"prompt_number": 29
},
{
"cell_type": "markdown",
......@@ -1224,7 +1287,7 @@
"cell_tags": []
},
"outputs": [],
"prompt_number": 28
"prompt_number": 30
},
{
"cell_type": "markdown",
......@@ -1261,7 +1324,7 @@
]
}
],
"prompt_number": 29
"prompt_number": 31
},
{
"cell_type": "markdown",
......@@ -1297,7 +1360,7 @@
]
}
],
"prompt_number": 30
"prompt_number": 32
},
{
"cell_type": "markdown",
......@@ -1363,7 +1426,7 @@
]
}
],
"prompt_number": 31
"prompt_number": 33
},
{
"cell_type": "markdown",
......@@ -1455,7 +1518,7 @@
]
}
],
"prompt_number": 32
"prompt_number": 34
},
{
"cell_type": "markdown",
......
......@@ -370,19 +370,48 @@ individual element of the array. Thus:
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
the value of the *corresponding* elements in `data`.
<pre class="in"><code>print &#39;original:&#39;
print data[:3, 36:]
print &#39;doubledata:&#39;
print doubledata[:3, 36:]</code></pre>
<div class="out"><pre class='out'><code>original:
[[ 2. 3. 0. 0.]
[ 1. 1. 0. 1.]
[ 2. 2. 1. 1.]]
doubledata:
[[ 4. 6. 0. 0.]
[ 2. 2. 0. 2.]
[ 4. 4. 2. 2.]]
</code></pre></div>
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>
<pre class="in"><code>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.
<pre class="in"><code>print &#39;tripledata:&#39;
print tripledata[:3, 36:]</code></pre>
<div class="out"><pre class='out'><code>tripledata:
[[ 6. 9. 0. 0.]
[ 3. 3. 0. 3.]
[ 6. 6. 3. 3.]]
</code></pre></div>
Often, we want to do more than add, subtract, multiply, and divide values of data.
Arrays also know how to do more complex operations on their values.
If we want to find the average inflammation for all patients on all days,
......
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