Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

iterate through paired values in dictionary

$
0
0
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?

Code:

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


Viewing all articles
Browse latest Browse all 2485

Trending Articles