def update_residue(rating_matrix, rate_bar):
    """update residue matrix for each iteration in Gradient descent method

    :param rating_matrix: users' rating matrix
    :param rate_bar: rating matrix generate by approximation in each GD step
    :return residue: residue matrix, rating_matrix - rate_bar
    :rtype: ndarray
    """

    residue = rating_matrix - rate_bar
    index = (rating_matrix == 0)
    residue[index] = 0

    return residue