<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def samples(self, n=None, sorted_by='energy'):
 """Return an iterable over the samples. Args: n (int, optional, default=None):
 Maximum number of samples to return in the view. sorted_by (str/None, optional, default='energy'):
 Selects the record field used to sort the samples. If None, samples are returned in record order. Returns: :obj:`.SamplesArray`: A view object mapping variable labels to values. Examples: {'a': -1, 'b': 1} {'a': 1, 'b': -1} {'a': -1, 'b': -1} {'a': 1, 'b': 1} {'a': -1, 'b': 1} -1 array([ 1, -1], dtype=int8) array([[ 1, -1], [-1, -1], [ 1, 1]], dtype=int8) """

        if n is not None:
            return self.samples(sorted_by=sorted_by)[:n]

        if sorted_by is None:
            samples = self.record.sample
        else:
            order = np.argsort(self.record[sorted_by])
            samples = self.record.sample[order]

        return SamplesArray(samples, self.variables)