How to assign a index based formula to each indexed position of a tensor on sympy

Viewed 77

Let's say that we have a IndexedBase 2-dim tensor r[i,j]. I want to assign to each indexed position a formula that uses the i and j positions of other 1-dim tensors, like this.

from sympy import symbols, IndexedBase, Idx
from sympy.functions.elementary.exponential import *

N = symbols('N', integer=True)
Np = symbols('Np', integer=True)

x = IndexedBase('x', (Np,))
z = IndexedBase('z', (Np,))
r = IndexedBase('r', (Np,N,))

i = Idx('i', (1,Np))
j = Idx('j', (1,N))

r[i,j] = sqrt(x[i]**2 + z[j]**2)

I know that could be easily translated to numpy, but sympy does not allow item association IndexedBase objects.

I need to understand how sympy treats the IndexedBase variables on this case. The final objective is to use lambdify on a much more complex expression, in order to allow numpy vectors as input arguments, but the operations are all based at this type of association. How could I perform this task?

Maybe I did not uderstand correctly the basis of the IndexedBase variables in Sympy. Sorry if this is a dummy question.

0 Answers
Related