<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_model(self, filename='scores', filepath='', output_format='csv'):
 """ This method calculates the scores and writes them to a file the data frame received. If the output format is other than 'csv' it will print the scores. :param filename: the name to give to the file :type filename: string :param filepath: the path to save the file :type filepath: string :param output_format: the format of the file to write ('csv') :type output_format: string """

        scores_array = np.array([])
        for obs in self.observations:
            c, sd = self.__get_centroids_sd(obs)
            points, ids = self.__get_features_for_observation(observation=obs, last_column_is_id=True)

            b = np.array([])
            for p in points:
                b = np.append(b, [self.get_single_score(p, centroids=c, sd=sd)])

            scores_array = np.vstack([scores_array, b]) if scores_array.size else b

        scores_array = np.concatenate((ids[:, np.newaxis], scores_array.transpose()), axis=1)
        header = 'id,'+','.join(self.observations)

        try:
            if output_format == 'csv':
                filename = join(filepath, filename) + '.' + output_format
                np.savetxt(filename, scores_array, delimiter=",", fmt='%i', header=header,comments='')
            else:
                print(scores_array)
        except:
            logging.error("Unexpected error on writing output")