@@ -229,48 +229,33 @@ np.std(v)
2292292 . Compute its mean and standard deviation.
2302303 . Try the same with a Python list. What happens?
231231
232- ---
233-
234- ## Mathematical background
235-
236- For a vector with values:
237-
238- \[
239- x_1, x_2, x_3, \dots, x_n
240- \]
241-
242- ### Mean
243-
244- The ** mean** (average) is:
245232
246- \[
247- \mu = \frac{1}{n} \sum_ {i=1}^{n} x_i
248- \]
233+ Steps:
234+ 1 . Subtract the mean from each value
235+ 2 . Square the differences
236+ 3 . Compute the mean of those squared differences
237+ 4 . Take the square root
249238
250- This means:
251- - Add up all values
252- - Divide by the number of values
253239
254- ---
240+ ??? exercise "Solution"
241+ ```python
242+ import numpy as np
255243
256- ### Standard deviation
244+ # 1. Create vector
245+ v = np.arange(0, 101, 10)
246+ v
257247
258- The ** standard deviation** measures how much the values vary around the mean.
248+ # 2. Mean and standard deviation
249+ np.mean(v)
250+ np.std(v)
259251
260- Population standard deviation:
252+ # 3. Try the same with a Python list
253+ lst = list(range(0, 101, 10))
261254
262- \[
263- \sigma = \sqrt{
264- \frac{1}{n}
265- \sum_ {i=1}^{n} (x_i - \mu)^2
266- }
267- \]
268-
269- Steps:
270- 1 . Subtract the mean from each value
271- 2 . Square the differences
272- 3 . Compute the mean of those squared differences
273- 4 . Take the square root
255+ # This will fail:
256+ np.mean(lst)
257+ np.std(lst)
258+ ```
274259
275260---
276261
0 commit comments