Unverified Commit fab35842 authored by Toan Phung's avatar Toan Phung Committed by GitHub

02-numpy.md: Update numpy.diff example to use patient data (#782)

* Update 02-numpy.md

Changing `numpy.diff` example to use data from the inflammation dataset.

As well as adding introduction to usage `axis` parameter of `numpy.diff` in the 2D multi-dimensinal array.

* Update 02-numpy.md

Change `row_start` variable name to `patient3_week1`.

Modify wording for the 2D array `numpy.diff` example question.

* Adding decimer indicator for number within numpy array

* Add printing statement for viewing of patient3_week1 data
parent 264020e0
......@@ -665,38 +665,44 @@ which is the average inflammation per patient across all days.
> with NumPy.
>
> The `numpy.diff()` function takes an array and returns the differences
> between two successive values. First we consider a one-dimensional
> array of length 5. This could be part of some row `i` of our inflammation data,
> i.e. `row_start = data[i,:5]`.
>
> between two successive values. Let's use it to examine the changes
> each day across the first week of patient 3 from our inflammation dataset.
>
> ~~~
> row_start = numpy.array([ 0, 2, 5, 9, 14])
> patient3_week1 = data[3, :7]
> print(patient3_week1)
> ~~~
> {: .language-python}
>
> Calling `numpy.diff(row_start)` would do the following calculations
> ~~~
> [0. 0. 2. 0. 4. 2. 2.]
> ~~~
> {: .output}
>
> Calling `numpy.diff(patient3_week1)` would do the following calculations
>
> ~~~
> [ 2 - 0, 5 - 2, 9 - 5, 14 - 9 ]
> [ 0 - 0, 2 - 0, 0 - 2, 4 - 0, 2 - 4, 2 - 2 ]
> ~~~
> {: .language-python}
>
> and return the 4 difference values in a new array.
> and return the 6 difference values in a new array.
>
> ~~~
> numpy.diff(row_start)
> numpy.diff(patient3_week1)
> ~~~
> {: .language-python}
>
> ~~~
> array([2, 3, 4, 5])
> array([ 0., 2., -2., 4., -2., 0.])
> ~~~
> {: .output}
>
> Note that the array of differences is shorter by one element (length 4).
> Note that the array of differences is shorter by one element (length 6).
>
> When applying `numpy.diff` to our 2D inflammation array `data`, which axis
> would it make sense to use this function along?
> When calling `numpy.diff` with a multi-dimensional array, an `axis` argument may
> be passed to the function to specify which axis to process. When applying
> `numpy.diff` to our 2D inflammation array `data`, which axis would we specify?
>
> > ## Solution
> > Since the row axis (0) is patients, it does not make sense to get the
......
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