python - Substituting an indexed variable with an expression -


i have sum on a[i] , want change sum on b[i] / 2.

i can change sum on b[i] this:

from sympy import * sympy.abc import * = indexedbase('a') b = indexedbase('b') sa = sum(a[i], (i, a, b)) sb = sa.subs(a, b) 

but want effect of

sb2 = sa.subs(a,b/2) 

any ideas?

the solution use replace instead of subs. haven't grok'ed difference, more info can found in difference between replace , subs?

sb.replace(a[i], b[i]/2) 

which returns

sum(b[i]/2, (i, a, b)) 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -