@@ -1135,3 +1135,82 @@ the graphs will actually be squeezed together more closely.)
11351135> > {: .output}
11361136> {: .solution}
11371137{: .challenge}
1138+
1139+ >## Change In Inflamation
1140+ >
1141+ >This patient data is _longitudinal_ in the sense that each row represents a
1142+ >series of observations relating to one individual. This means that change
1143+ >inflamation is a meaningful concept.
1144+ >
1145+ >The `numpy.diff()` function takes a NumPy array and returns the
1146+ >difference along a specified axis.
1147+ >
1148+ >Which axis would it make sense to use this function along?
1149+ >
1150+ > > ## Solution
1151+ > > Since the row axis (0) is patients, it does not make sense to get the
1152+ > > difference between two arbitrary patients. The column axis (1) is in
1153+ > > days, so the differnce is the change in inflamation -- a meaningful
1154+ > > concept.
1155+ > >
1156+ > > ~~~
1157+ > > numpy.diff(data, axis=1)
1158+ > > ~~~
1159+ > > {: .python}
1160+ > {: .solution}
1161+ >
1162+ >If the shape of an individual data file is `(60, 40)` (60 rows and 40
1163+ >columns), what would the shape of the array be after you run the `diff()`
1164+ >function and why?
1165+ >
1166+ > > ## Solution
1167+ > > The shape will be `(60, 39)` because there is one fewer difference between
1168+ > > columns than there are columns in the data.
1169+ > {: .solution}
1170+ >
1171+ >How would you find the largest change in inflammation for each patient? Does
1172+ >it matter if the change in inflammation is an increase or a decrease?
1173+ >
1174+ > > ## Solution
1175+ > > By using the `numpy.max()` function after you apply the `numpy.diff()`
1176+ > > function, you will get the largest difference between days.
1177+ > >
1178+ > > ~~~
1179+ > > numpy.max(numpy.diff(data, axis=1), axis=1)
1180+ > > ~~~
1181+ > > {: .python}
1182+ > >
1183+ > > ~~~
1184+ > > array([ 7., 12., 11., 10., 11., 13., 10., 8., 10., 10., 7.,
1185+ > > 7., 13., 7., 10., 10., 8., 10., 9., 10., 13., 7.,
1186+ > > 12., 9., 12., 11., 10., 10., 7., 10., 11., 10., 8.,
1187+ > > 11., 12., 10., 9., 10., 13., 10., 7., 7., 10., 13.,
1188+ > > 12., 8., 8., 10., 10., 9., 8., 13., 10., 7., 10.,
1189+ > > 8., 12., 10., 7., 12.])
1190+ > > ~~~
1191+ > > {: .python}
1192+ > >
1193+ > > If a difference is a *decrease*, then the difference will be negative. If
1194+ > > you are interested in the **magnitude** of the change and not just the
1195+ > > direction, the `numpy.absolute()` function will provide that.
1196+ > >
1197+ > > Notice the difference if you get the largest _absolute_ difference
1198+ > > between readings.
1199+ > >
1200+ > > ~~~
1201+ > > numpy.max(numpy.absolute(numpy.diff(data, axis=1)), axis=1)
1202+ > > ~~~
1203+ > > {: .python}
1204+ > >
1205+ > > ~~~
1206+ > > array([ 12., 14., 11., 13., 11., 13., 10., 12., 10., 10., 10.,
1207+ > > 12., 13., 10., 11., 10., 12., 13., 9., 10., 13., 9.,
1208+ > > 12., 9., 12., 11., 10., 13., 9., 13., 11., 11., 8.,
1209+ > > 11., 12., 13., 9., 10., 13., 11., 11., 13., 11., 13.,
1210+ > > 13., 10., 9., 10., 10., 9., 9., 13., 10., 9., 10.,
1211+ > > 11., 13., 10., 10., 12.])
1212+ > > ~~~
1213+ > > {: .python}
1214+ > >
1215+ > {: .solution}
1216+ {: .challenge}
0 commit comments