Coverage for pyguymer3/stderr.py: 67%

9 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-08 18:47 +0000

1#!/usr/bin/env python3 

2 

3# Define function ... 

4def stderr( 

5 arr, 

6 /, 

7 *, 

8 dof = 1, 

9): 

10 """Find the standard error of an array. 

11 

12 This function finds the standard error of an array, with optionally 

13 specified degrees of freedom. 

14 

15 Parameters 

16 ---------- 

17 arr : numpy.ndarray 

18 the array 

19 dof : int, default=1 

20 the degrees of freedom 

21 

22 Returns 

23 ------- 

24 ans : float 

25 the standard error of the array 

26 

27 Notes 

28 ----- 

29 See `the SciPy documentation <https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.sem.html>`_. 

30 

31 Copyright 2017 Thomas Guymer [1]_ 

32 

33 References 

34 ---------- 

35 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3 

36 """ 

37 

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 

43 

44 # Import sub-functions ... 

45 from .stddev import stddev 

46 

47 # Check argument ... 

48 if not isinstance(arr, numpy.ndarray): 

49 raise TypeError("\"arr\" is not a NumPy array") from None 

50 

51 # Return answer ... 

52 return stddev(arr, dof = dof) / numpy.sqrt(arr.size)