5

I have a question, is it posible to iterate in a loop in different cells in a notebook? for instance I have this code:

for c in range(2):
# Thetas
thetas = np.zeros((J,I))
it = np.nditer(thetas, flags=['multi_index'],op_flags=['writeonly'])
while not it.finished:
    i=it.multi_index[1]
    j=it.multi_index[0]
    coefs=np.array([1-(K/(prod[j]*la[j]*firm[i])),(-K/(prod[j]*firm[i]))*(1+(1/la[j])),-K/(prod[j]*firm[i])])
    sol=np.roots(coefs)
    it[0]=np.amax((sol))
    it.iternext()

# Wages
wag=np.zeros((J,I))
it = np.nditer(wag, flags=['multi_index'],op_flags=['writeonly'])
while not it.finished:
    i=it.multi_index[1]
    j=it.multi_index[0]
    it[0]=prod[j]*firm[i]-(K*(1+thetas[j,i])/(la[j]*thetas[j,i]))
    it.iternext()

And for demonstration purposes i'd like to run the thetas code in a cell, display some results, then run the wages, display another result, and then iterate for the second time on theta and wages. Is this at all possible?

Thanks

Thomas K
  • 39,200
  • 7
  • 84
  • 86
user3207377
  • 95
  • 1
  • 1
  • 8
  • 1
    I'm not entirely sure what you're asking. You can't split a `for` loop over multiple cells, but you could set up `it = iter(range(2))` and then step through it manually with `c = next(it)`. – Thomas K May 17 '16 at 17:10
  • I meant the former, sadly – user3207377 May 17 '16 at 22:02
  • 2
    Possible duplicate of [Run parts of a ipython notebook in a loop / with different input parameter](http://stackoverflow.com/questions/15635341/run-parts-of-a-ipython-notebook-in-a-loop-with-different-input-parameter) – KeithWM May 18 '17 at 09:03
  • I have found a reasonable workaround to this in a question of which this is a duplicate (more or less), see metakermit's answer on http://stackoverflow.com/questions/15635341/run-parts-of-a-ipython-notebook-in-a-loop-with-different-input-parameter – KeithWM May 18 '17 at 09:04

0 Answers0