Numerical Module¶
-
class
riccipy.numerical.
NumericalArray
(args, array, **kwargs)¶ Bases:
object
Class for representing an array of symbolic expressions as lambdified functions.
Calling instances of this class will result in the evaluation of a lambda function that returns a numerically valued array representing the results of the individual component expressions.
Furthermore, instances may also be used to access specific components in a manner identical to accessing the components of an numpy array.
-
riccipy.numerical.
lambdify_tensor
(args, expr, idxs=None, **kwargs)¶ Generate a numerical array representation for the result of a tensor expression.
When the tensor expression passed results in an instance of ~sympy.Array, a NumericalArray object is returned. A NumericalArray can be used to access lambda functions for either the array as a whole or for individual components. See the example below.
Parameters: - args ((list, tuple)) – Iterable of ~sympy.Symbol objects that specifcy the order of the arguments for the lambda functions that will be generated.
- expr ((TensExpr, Expr)) – The tensor expression to be lambdified. If this is an ordinary expression this function defaults to ~sympy.lambdify.
- idxs ((list, tuple)) – Iterable of Index objects to specify the indices for the result of
expr
.
Examples
>>> from sympy import diag, sin, symbols >>> from riccipy import Metric, lambdify_tensor, indices >>> t, r, th, ph = symbols('t r theta phi', real=True) >>> schw = diag(1-1/r, -1/(1-1/r), -r**2, -r**2*sin(th)**2) >>> g = Metric('g', (t, r, th, ph), schw) >>> mu, nu = indices('mu nu', g) >>> narr = lambdify_tensor((r, th), g(-mu,-nu)) >>> narr(2, 0) array([[ 0.5, 0. , 0. , 0. ], [ 0. , -2. , 0. , 0. ], [ 0. , 0. , -4. , 0. ], [ 0. , 0. , 0. , -0. ]]) >>> narr[0,0] <function _lambdifygenerated at 0x...> >>> narr[0,0](2, 0) 0.5