khan18

iterate through paired values in dictionary

Discussion created by khan18 on Nov 17, 2012
Latest reply on Nov 21, 2012 by khan18
I have converted grid1 and grid2 into arrays using numpy and using following function which iterates through table and should return corresponding value form table when grid1 and grid2 values are matched. But somehow the final output contain only 4 integer values which isn't correct. Any suggestion what is possibly wrong here?

def grid(grid1,grid2):
    table = {(10,1):61,(10,2):75,(10,3):83,(10,4):87,
             (11,1):54,(11,2):70,(11,3):80,(11,4):85,
             (12,1):61,(12,2):75,(12,3):83,(12,4):87,
             (13,1):77,(13,2):85,(13,3):90,(13,4):92,}
    grid3 = np.zeros(grid1.shape, dtype = np.int)

    for k,v in table.iteritems():
        grid3[[grid1 == k[0]] and [grid2 == k[1]]] = v

    return grid3

Outcomes