def iterate_grid(a, (p,q)):    
    ''' generate the next sub matrix from the original matrix
    
    yield the sub matrix back to be consumed

    Parameters
    ----------

        all parameters are keyword parameters

        a : parent matrix
            represents the larger parent matrix

        (p,q): tuple
            represents the dimensions of each sub
            matrix to generate

    Returns
    -------
        
        yields the next sub matrix 

    '''
    row, col = np.shape(a)
    #print row,col
    for (r,c) in ((r,c) for r in np.arange(row-p+2) for c in np.arange(col-q+2)):   	
	 if r ==0 and c == 0: #corner
		yield (r,r+q, c,c+q), (r,c), (0,0), np.matrix(a[r:r+q, c:c+q]), 'corner'   
	 elif r ==0 and c != 0: #top
		yield (r,r+q, c-1,c+q), (r,c), (0,1), np.matrix(a[r:r+q, c-1:c+q]) , 'top'
	 elif r !=0 and c == 0: # edge,
		yield (r-1,r+q, c,c+q), (r,c), (1,0), np.matrix(a[r-1:r+q, c:c+q]) , 'edge'   
	 else: # normal body 
		yield (r-1,r+p, c-1,c+q), (r,c), (1,1), np.matrix(a[r-1:r+p, c-1:c+q])  , 'body'
 generate the next sub matrix from the original matrix
    
    yield the sub matrix back to be consumed

    Parameters
    ----------

        all parameters are keyword parameters

        a : parent matrix
            represents the larger parent matrix

        (p,q): tuple
            represents the dimensions of each sub
            matrix to generate

    Returns
    -------
        
        yields the next sub matrix 

    
recipes/Python/578559_Conways_Game_of_Life_In_Python/recipe-578559.py