0

I'm trying to get sympy to substitute a symbol for two other symbols on the basis of iteration. At the moment I have some code that does an expansion of some brackets and stores each iteration:

for i in range(0,nMoments-1):
  middle.append(K+i)

Producing

[K]
[K, K + 1]
[K, K + 1, K + 2]

What I would like to do is for each row substitute two symbols for K, which are themselves stored in vectors of equal length m1 and m2. So for the top row, for each K I would like to substitute m1[0]/m2[0], then for each K in the second row m1[1]/m2[1], for K in the third row m1[2]/m2[2] e.t.c

So that for middle[0] the equiv indexation of the m1 and m2 vectors are put into K.

For reference, nMoments is just an int variable

From what I can tell, my closest attempt so far is

for i in range(0,nMoments):
  K.replace(K,m1[i]**2/m2[i])
  print middle

However this produces this:

[K, K + 1, K + 2]
[K, K + 1, K + 2]
[K, K + 1, K + 2]

Does anyone know how I can resolve this issue?

Many thanks!

user124123
  • 1,642
  • 7
  • 30
  • 50

1 Answers1

1

Is this what you want?

for i in range(nMoments):
    middle[i] = middle[i].subs(K, m1[i]**2/m2[i])
asmeurer
  • 86,894
  • 26
  • 169
  • 240
  • This didn't work, in the end did the process the other way round from how I described it in the original question but many thanks anyway! – user124123 May 21 '13 at 12:45