import math


def recreate_2DFES(FES, icount, coords, xinc, xmin, xmax, yinc, ymin, ymax, E):
    """
    Receive and returns an array that recreates the FES.

    Parameters:
    -----------
        FES     : Array of floats
                  Energy values corresponding to x location on x dimension

        icount  : Array of integers
                  Stores number of counts sampled at each location

        coord   : float
                  location of walker

        xinc    : float
                  increment of grid

        xmin    : float
                  minimum value in grid

        xmax    : float
                  maximum value in grid

        yinc    : float
                  increment of grid

        ymin    : float
                  minimum value in grid

        ymax    : float
                  maximum value in grid

        E       : float
                  Energy value to be stored

    Returns:
    --------
        FES     : Array of floats
                  Energy values corresponding to x location on x dimension
                  (updated)

        icount  : Array of integers
                  Number of counts sampled at each location (updated)
    """
    xindex = int(round((round(coords[0],
                        int(abs(math.log10(xinc)))) +
                        (0 - xmin)) / xinc))

    yindex = int(round((round(coords[1],
                        int(abs(math.log10(yinc)))) +
                        (0 - ymin)) / yinc))
    if (coords[0] > xmin and coords[0] < xmax and
            coords[1] > ymin and coords[1] < ymax):

        FES[yindex, xindex] = ((FES[yindex, xindex] *
                               (icount[yindex, xindex]) + E) /
                               (icount[yindex, xindex] + 1))
        icount[yindex, xindex] = icount[yindex, xindex] + 1

    return (FES, icount)