Skip to content

Commit

Permalink
add short example with SetParameters from numpy array
Browse files Browse the repository at this point in the history
  • Loading branch information
skkwan authored and vepadulano committed Nov 27, 2024
1 parent c72a2f9 commit 8db2ac8
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def func(x: numpy.ndarray, pars: numpy.ndarray) -> float:
\endcode
Second, after performing the initialisation with a Python functor, the TF1 instance can be evaluated using the Pythonized
`TF1::EvalPar` function. The pythonization allows passing in 1D(single set of x variables) or 2D(a dataset) NumPy arrays.
TF1.EvalPar function. The pythonization allows passing in 1D(single set of x variables) or 2D(a dataset) NumPy arrays.
The following example shows how we can create a TF1 instance with a Python function and evaluate it on a dataset:
Expand Down Expand Up @@ -59,6 +59,22 @@ def pyf_tf1_coulomb(x, p):
res = rtf1_coulomb.EvalPar(x[:, ::2], params)
\endcode
The below example defines a TF1 instance using the ROOT constructor, and sets its parameters using the Pythonized TF1.SetParameters function (i.e. without evaluating).
\code{.py}
import numpy as np
# for illustration, a sinusoidal function with six parameters
myFunction = ROOT.TF1("myExampleFunction", "[0] + [1] * x + [2]*sin([3] * x) + [4]*cos([5] * x)", -5, 5)
# declare the parameters as a numpy.array or array.array
myParams = np.array([0.04, 0.4, 3.0, 3.14, 1.5, 3.14])
# note: the following line would also work by setting all six parameters equal to 3.0
# myParams = np.array([3.0] * 6)
myFunction.SetParameters(myParams)
\endcode
\endpythondoc
"""

Expand Down

0 comments on commit 8db2ac8

Please sign in to comment.