<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _calculate_weights(self, this_samples, N):
 """Calculate and save the weights of a run."""


        this_weights = self.weights.append(N)[:,0]

        if self.target_values is None:
            for i in range(N):
                tmp = self.target(this_samples[i]) - self.proposal.evaluate(this_samples[i])
                this_weights[i] = _exp(tmp)
        else:
            this_target_values = self.target_values.append(N)
            for i in range(N):
                this_target_values[i] = self.target(this_samples[i])
                tmp = this_target_values[i] - self.proposal.evaluate(this_samples[i])
                this_weights[i] = _exp(tmp)