Coverage for pyguymer3/mean.py: 62%
8 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 mean(
5 arr,
6 /,
7 *,
8 dof = 0,
9):
10 """Find the arithmetic mean of an array.
12 This function finds the arithmetic mean 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 arithmetic mean of the array
27 Notes
28 -----
29 See `the NumPy documentation <https://numpy.org/doc/stable/reference/generated/numpy.mean.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 # Check argument ...
45 if not isinstance(arr, numpy.ndarray):
46 raise TypeError("\"arr\" is not a NumPy array") from None
48 # Return answer ...
49 return arr.sum() / (arr.size - dof)