Commit d89353a0 authored by Johnny Lin's avatar Johnny Lin
Browse files

Add brief description of array syntax

The description uses a few examples to illustrate how array syntax works for arithmetic operators.  Transition text is also added.
parent 5d0c4990
......@@ -361,6 +361,26 @@ print small</code></pre>
Arrays also know how to perform common mathematical operations on their values.
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.
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,
for example,
we can just ask the array for its mean value
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