<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_samples(self, samples, parameters=None, last_iteration=None):
 """Writes samples to the given file. Results are written to ``samples_group/{vararg}``, where ``{vararg}`` is the name of a model params. The samples are written as an ``nwalkers x niterations`` array. If samples already exist, the new samples are appended to the current. If the current samples on disk have been thinned (determined by the ``thinned_by`` attribute in the samples group), then the samples will be thinned by the same amount before being written. The thinning is started at the sample in ``samples`` that occured at the iteration equal to the last iteration on disk plus the ``thinned_by`` interval. If this iteration is larger than the iteration of the last given sample, then none of the samples will be written. Parameters samples : dict The samples to write. Each array in the dictionary should have shape nwalkers x niterations. parameters : list, optional Only write the specified parameters to the file. If None, will write all of the keys in the ``samples`` dict. last_iteration : int, optional The iteration of the last sample. If the file's ``thinned_by`` attribute is > 1, this is needed to determine where to start thinning the samples such that the interval between the last sample currently on disk and the first new sample is the same as all of the other samples. """

        nwalkers, nsamples = list(samples.values())[0].shape
        assert all(p.shape == (nwalkers, nsamples)
                   for p in samples.values()), (
               "all samples must have the same shape")
        group = self.samples_group + '/{name}'
        if parameters is None:
            parameters = samples.keys()
        # thin the samples
        samples = thin_samples_for_writing(self, samples, parameters, last_iteration)
        # loop over number of dimensions
        for param in parameters:
            dataset_name = group.format(name=param)
            data = samples[param]
            # check that there's something to write after thinning
            if data.shape[1] == 0:
                # nothing to write, move along
                continue
            try:
                fp_nsamples = self[dataset_name].shape[-1]
                istart = fp_nsamples
                istop = istart + data.shape[1]
                if istop > fp_nsamples:
                    # resize the dataset
                    self[dataset_name].resize(istop, axis=1)
            except KeyError:
                # dataset doesn't exist yet
                istart = 0
                istop = istart + data.shape[1]
                self.create_dataset(dataset_name, (nwalkers, istop),
                                    maxshape=(nwalkers, None),
                                    dtype=data.dtype,
                                    fletcher32=True)
            self[dataset_name][:, istart:istop] = data