Solved by ruka in post #2 
              
              
                The formula would be 

numpy.floor([ y/image_size * grid_size, x/image_size * grid_size ]) 

Assume your input image is 256 * 256, and the center of a target is (y=10, x=123), your grid size is 7 * 7. 
Then the center would fall in numpy.floor([ 10/256 * 7, 123/256 * 7 ]) = [0, 3],  aka grid[0][3].