why cannot recalculate?

asked 2012-03-24 08:21:07 +0100

canisvetus gravatar image

updated 2012-03-26 16:39:53 +0100

Shashank gravatar image

These code work fine

html("<h1> From Dictionary to Matrix (1)</h1>")
    @interact
    def newtarph( D=input_box(default={0:{1:3}, 1: {0: 2, 4: 2, 5: 2}, 2: {0: 3, 1: 4}}, label='Dictionary')):
        E=[]
        for u in D.keys():
            for i in range(len(D.values()[u])):        
              E.append([u, D.values()[u].keys()[i], D.values()[u].values()[i]])
        print matrix(E)

These other code d'ont work:

html("<h1> From Dictionary to Matrix (1)</h1>")
    @interact
    def newtarph( D=input_box(default={1: {0: 2, 4: 2, 5: 2}, 2: {0: 3, 1: 4}}, label='Dictionary')):
        E=[]
        for u in D.keys():
            for i in range(len(D.values()[u])):        
              E.append([u, D.values()[u].keys()[i], D.values()[u].values()[i]])
        print matrix(E)
edit retag flag offensive close merge delete

Comments

What is your question exactly? Seems to work for me

Shashank gravatar imageShashank ( 2012-03-24 08:57:13 +0100 )edit

Yes, seems to work, but if you modifie the dictionary, you can obtein an error

canisvetus gravatar imagecanisvetus ( 2012-03-24 15:53:58 +0100 )edit

Modifying the dictionary seems to work fine for me. Can you tell us exactly how to modify it and exactly what the error is (just copy and paste the error message.)

Jason Grout gravatar imageJason Grout ( 2012-03-24 21:11:57 +0100 )edit

Excuse me Shashank and Jason Grout. Perhaps I make a mistake writen the dictionary. Now work also for me. Eusebio Corbacho.

canisvetus gravatar imagecanisvetus ( 2012-03-25 05:08:01 +0100 )edit

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_20.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("X2ludGVyYWN0Xy51cGRh\ dGUoJzQwJywgJ0QnLCA0LCBfaW50ZXJhY3RfLnN0YW5kYXJkX2I2NGRlY29kZSgnZXpFNklI\ c3dPaUF6TENBeU9pQTBmU3dnTWpvZ2V6TTZJRElzSURRNklERjlMQ0F6T2lCN01Eb2dNaXdn\ TVRvZ015d2dORG9nTVgxOScpLCBnbG9iYWxzKCkpOyBfaW50ZXJhY3RfLnJlY29tcHV0ZSgn\ NDAnKTs="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpx7r7GI/___code___.py", line 3, in <module> exec compile(u"_interact_.update('40', 'D', _sage_const_4 , _interact_.standard_b64decode('ezE6IHswOiAzLC

canisvetus gravatar imagecanisvetus ( 2012-03-25 05:59:12 +0100 )edit

AyOiA0fSwgMjogezM6IDIsIDQ6I\ DF9LCAzOiB7MDogMiwgMTogMywgNDogMX19'), globals()); _interact_.recompute('40');" + '\n', '', 'single') File "", line 1, in <module> File "/home/sage/sage/devel/sagenb/sagenb/notebook/interact.py", line 3770, in recompute S['function']() File "/home/sage/sage/devel/sagenb/sagenb/notebook/interact.py", line 2572, in _ z = f(*[variables[arg] for arg in args]) File "/tmp/tmpiy2_h0/___code___.py", line 8, in newtarph for i in range(len(D.values()[u])): IndexError: list index out of range

canisvetus gravatar imagecanisvetus ( 2012-03-25 06:00:19 +0100 )edit

Hello Jason Grout, Really dont work. The error message is include in the two previus commentaries. for obtain these error I take the dictionary D={0: {1: 2, 2: 3}, 1: {0: 3, 2: 4}, 2: {3: 2, 4: 1}, 3: {0: 2, 1: 3, 4: 1}} and suprime in a second step 0: {1: 2, 2: 3}. Thank you for your help.

canisvetus gravatar imagecanisvetus ( 2012-03-25 06:06:31 +0100 )edit