human
Complete this python program:
def _masked_objective(fn):
assistant
#Here is the Python code you requested.

    """Adds support for masking to an objective function.
    It transforms an objective function `fn(y_true, y_pred)`
    into a cost-masked objective function
    `fn(y_true, y_pred, mask)`.
    # Arguments
    fn: The objective function to wrap,
    with signature `fn(y_true, y_pred)`.
    # Returns
    A function with signature `fn(y_true, y_pred, mask)`.
    """
    def masked(y_true, y_pred, mask=None):
        'Wrapper    function.\n\n                                #    Arguments\n                                                y_true:    `y_true`    argument    of    `fn`.\n                                                y_pred:    `y_pred`    argument    of    `fn`.\n                                                mask:    Mask    tensor.\n\n                                #    Returns\n                                                Scalar    tensor.\n                                '
        score_array = fn(y_true, y_pred)
        if (mask is not None):
            mask = K.cast(mask, K.floatx())
            score_array *= mask
            score_array /= K.mean(mask)
        return K.mean(score_array)
    return masked