ajustador.vartype¶
-
class
ajustador.vartype.
vartype
(x, dev=0)[source]¶ A number with an uncertainty (σ)
>>> x = vartype(123, 5) >>> y = vartype(8, 1) >>> x + y vartype(131.0, 5.1) >>> x - y vartype(115.0, 5.1) >>> y / 3 vartype(2.67, 0.33) >>> y < y False >>> print(y) 8±1 >>> print(x) 123±5
-
positive
¶ Check if the number is greater than 3σ
>>> x = vartype(4, 1) >>> x.positive True >>> y = x - vartype(3) >>> y vartype(1.0, 1.0) >>> y.positive False
-
negative
¶ Check if the number is smaller than -3σ
>>> x = vartype(-4, 1) >>> x.negative True
-
classmethod
average
(vect)[source]¶ Calculate a weighted average of an array
>>> items = [vartype(x, 1 + x/10) for x in range(5)] >>> X = vartype.array(items) >>> print(X) rec.array([(0, 1.0), (1, 1.1), (2, 1.2), (3, 1.3), (4, 1.4)], dtype=[('x', '<i8'), ('dev', '<f8')]) >>> vartype.average(X) vartype(1.66, 0.53)
-
classmethod
array
(items)[source]¶ Create an array of vartypes
The array is a numpy structured array with .x and .dev attributes.
>>> items = [vartype(x, 1 + x/10) for x in range(5)] >>> X = vartype.array(items) >>> X rec.array([(0, 1.0), (1, 1.1), (2, 1.2), (3, 1.3), (4, 1.4)], dtype=[('x', '<i8'), ('dev', '<f8')]) >>> X.x array([0, 1, 2, 3, 4]) >>> X.dev array([ 1. , 1.1, 1.2, 1.3, 1.4])
-
nan
= vartype(nan, nan)¶
-