Issue
Can I substitute a IndexedBase with a numpy array to get a new sympy expression? Something like:
import numpy as np
import sympy as sy
A = sy.IndexedBase('A', shape=(5))
k = sy.IndexedBase('k', shape=(5))
i = sy.symbols('i',cls=sy.Idx)
expr1 = sy.Sum(A[i]/sy.exp(sy.I * k[i]),(i,1,5))
kz = np.arange(1,5)
expr2 = expr1.subs(k[:],kz[:])
last line = error.
Thanks!
Solution
Yes, you can:
In [6]: expr2 = expr1.replace(k, kz)
In [7]: expr2
Out[7]:
5
___
╲
╲ -ⅈ⋅[1, 2, 3, 4, 5][i]
╱ ℯ ⋅A[i]
╱
‾‾‾
i = 1
Beware that the summation range is wrong, Python arrays have zero as offset.
Answered By - Francesco Bonazzi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.