Vectorized gamma_method (#207)

* feat: vectorized gamma_method function added.

* feat: vectorized gamma method generalized to also work on other objects
like Corr or Fit_result.

* feat: alias gamma_method for vectorized gamma_method added.

* docs: example 5 updated to include vectorized gamma_method.

* docs: output of example 5 updated.
This commit is contained in:
Fabian Joswig 2023-07-19 12:13:20 +01:00 committed by GitHub
parent 6b7846486d
commit 1e438356fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 46 deletions

View file

@ -1032,6 +1032,22 @@ class CObs:
return f"({self.real:{format_type}}{self.imag:+{significance}}j)"
def gamma_method(x, **kwargs):
"""Vectorized version of the gamma_method applicable to lists or arrays of Obs.
See docstring of pe.Obs.gamma_method for details.
"""
return np.vectorize(lambda o: o.gm(**kwargs))(x)
def gm(x, **kwargs):
"""Short version of the vectorized gamma_method.
See docstring of pe.Obs.gamma_method for details
"""
return gamma_method(x, **kwargs)
def _format_uncertainty(value, dvalue, significance=2):
"""Creates a string of a value and its error in paranthesis notation, e.g., 13.02(45)"""
if dvalue == 0.0 or (not np.isfinite(dvalue)):