1 |
|
2 |
|
3 | # Function std
|
4 |
|
5 | Compute the standard deviation of a matrix or a list with values.
|
6 | The standard deviations is defined as the square root of the variance:
|
7 | `std(A) = sqrt(variance(A))`.
|
8 | In case of a (multi dimensional) array or matrix, the standard deviation
|
9 | over all elements will be calculated by default, unless an axis is specified
|
10 | in which case the standard deviation will be computed along that axis.
|
11 |
|
12 | Additionally, it is possible to compute the standard deviation along the rows
|
13 | or columns of a matrix by specifying the dimension as the second argument.
|
14 |
|
15 | Optionally, the type of normalization can be specified as the final
|
16 | parameter. The parameter `normalization` can be one of the following values:
|
17 |
|
18 | - 'unbiased' (default) The sum of squared errors is divided by (n - 1)
|
19 | - 'uncorrected' The sum of squared errors is divided by n
|
20 | - 'biased' The sum of squared errors is divided by (n + 1)
|
21 |
|
22 |
|
23 | ## Syntax
|
24 |
|
25 | ```js
|
26 | math.std(a, b, c, ...)
|
27 | math.std(A)
|
28 | math.std(A, normalization)
|
29 | math.std(A, dimension)
|
30 | math.std(A, dimension, normalization)
|
31 | ```
|
32 |
|
33 | ### Parameters
|
34 |
|
35 | Parameter | Type | Description
|
36 | --------- | ---- | -----------
|
37 | `array` | Array | Matrix | A single matrix or or multiple scalar values
|
38 | `normalization` | string | Determines how to normalize the variance. Choose 'unbiased' (default), 'uncorrected', or 'biased'. Default value: 'unbiased'.
|
39 |
|
40 | ### Returns
|
41 |
|
42 | Type | Description
|
43 | ---- | -----------
|
44 | * | The standard deviation
|
45 |
|
46 |
|
47 | ## Examples
|
48 |
|
49 | ```js
|
50 | math.std(2, 4, 6) // returns 2
|
51 | math.std([2, 4, 6, 8]) // returns 2.581988897471611
|
52 | math.std([2, 4, 6, 8], 'uncorrected') // returns 2.23606797749979
|
53 | math.std([2, 4, 6, 8], 'biased') // returns 2
|
54 |
|
55 | math.std([[1, 2, 3], [4, 5, 6]]) // returns 1.8708286933869707
|
56 | math.std([[1, 2, 3], [4, 6, 8]], 0) // returns [2.1213203435596424, 2.8284271247461903, 3.5355339059327378]
|
57 | math.std([[1, 2, 3], [4, 6, 8]], 1) // returns [1, 2]
|
58 | math.std([[1, 2, 3], [4, 6, 8]], 1, 'biased') // returns [0.7071067811865476, 1.4142135623730951]
|
59 | ```
|
60 |
|
61 |
|
62 | ## See also
|
63 |
|
64 | [mean](mean.md),
|
65 | [median](median.md),
|
66 | [max](max.md),
|
67 | [min](min.md),
|
68 | [prod](prod.md),
|
69 | [sum](sum.md),
|
70 | [variance](variance.md)
|