mirror of
https://github.com/vale981/SecondaryValue
synced 2025-03-04 16:41:38 -05:00
fix list, add docs
This commit is contained in:
parent
297b02c4ff
commit
102f0dbc33
2 changed files with 31 additions and 2 deletions
28
Readme.md
28
Readme.md
|
@ -54,6 +54,34 @@ print(result)
|
|||
# symbolic form. (Works best in Jupyter Notebooks)
|
||||
x.pretty_gauss_propagation('a', 'b', 'c')
|
||||
```
|
||||
|
||||
### Vectorized Input
|
||||
`SecondaryValue` supports vectorized input. As a rule-of-thump: Put
|
||||
the iterable (list, np.array) where you would put scalars.
|
||||
|
||||
You can mix scalars and vectors as long as all errors and values are
|
||||
either scalar or have the same length.
|
||||
|
||||
```python
|
||||
from SecondaryValue import SecondaryValue
|
||||
x = SecondaryValue('a**2+b')
|
||||
|
||||
x(a=[[1,2,3]], b=1)
|
||||
# >> array([ 2., 5., 10.])
|
||||
|
||||
x(a=([1,2,3], 1), b=1)
|
||||
# >> (array([ 2., 5., 10.]), array([2., 4., 6.]))
|
||||
|
||||
x(a=([1,2,3], [1,2,3]), b=1)
|
||||
# >> (array([ 2., 5., 10.]), array([ 2., 8., 18.]))
|
||||
|
||||
x(a=([1,2,3], [1,2,3]), b=([1,2,3], 1))
|
||||
# >> (array([ 2., 6., 12.]), array([ 2.23606798, 8.06225775, 18.02775638]))
|
||||
|
||||
# THAT DOES NOT WORK:
|
||||
x(a=([1,2,3], [1,2,3]), b=([1,2], 1))
|
||||
```
|
||||
|
||||
### Dependencies
|
||||
To make the calculation of complex values easier, one can define
|
||||
dependencies for a `SecondaryValue`:
|
||||
|
|
|
@ -67,7 +67,7 @@ class SecondaryValue:
|
|||
continue
|
||||
|
||||
tmp = sec_val(**kwargs)
|
||||
kwargs[name] = tmp[0] if isinstance(tmp, Iterable) else tmp
|
||||
kwargs[name] = tmp
|
||||
calc_deps[name] = tmp
|
||||
|
||||
return kwargs, calc_deps
|
||||
|
@ -223,7 +223,8 @@ class SecondaryValue:
|
|||
|
||||
# calulate the central value
|
||||
scalar_values, vector_values = filter_out_vecotrized(values)
|
||||
central_value = self._calculate_central_value(scalar_values, vector_values)
|
||||
central_value = self._calculate_central_value(scalar_values,
|
||||
vector_values)
|
||||
|
||||
if not errors:
|
||||
return central_value
|
||||
|
|
Loading…
Add table
Reference in a new issue