<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def resid_dev(self, endog, mu, scale=1.):
 r""" Gamma deviance residuals Parameters endog : array-like Endogenous response variable mu : array-like Fitted mean response variable scale : float, optional An optional argument to divide the residuals by scale. The default is 1. Returns ------- resid_dev : array Deviance residuals as defined below """

        endog_mu = self._clean(endog / mu)
        return np.sign(endog - mu) * np.sqrt(-2 * (-(endog - mu)/mu +
                                                   np.log(endog_mu)))