Coverage for pyguymer3/stddev.py: 67%
9 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
1#!/usr/bin/env python3
3# Define function ...
4def stddev(
5 arr,
6 /,
7 *,
8 dof = 0,
9):
10 """Find the standard deviation of an array.
12 This function finds the standard deviation of an array, with optionally
13 specified degrees of freedom.
15 Parameters
16 ----------
17 arr : numpy.ndarray
18 the array
19 dof : int, default=0
20 the degrees of freedom
22 Returns
23 -------
24 ans : float
25 the standard deviation of the array
27 Notes
28 -----
29 See `the NumPy documentation <https://numpy.org/doc/stable/reference/generated/numpy.std.html>`_.
31 Copyright 2017 Thomas Guymer [1]_
33 References
34 ----------
35 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3
36 """
38 # Import special modules ...
39 try:
40 import numpy
41 except:
42 raise Exception("\"numpy\" is not installed; run \"pip install --user numpy\"") from None
44 # Import sub-functions ...
45 from .var import var
47 # Check argument ...
48 if not isinstance(arr, numpy.ndarray):
49 raise TypeError("\"arr\" is not a NumPy array") from None
51 # Return answer ...
52 return numpy.sqrt(var(arr, dof = dof))