dimod.SampleSet.truncate#

SampleSet.truncate(n, sorted_by='energy')[source]#

Create a new sample set with up to n rows.

Parameters:
  • n (int) – Maximum number of rows in the returned sample set. Does not return any rows above this limit in the original sample set.

  • sorted_by (str/None, optional, default='energy') – Selects the record field used to sort the samples before truncating. Note that this sort order is maintained in the returned sample set.

Returns:

SampleSet

Examples

>>> import numpy as np
...
>>> sampleset = dimod.SampleSet.from_samples(np.ones((5, 5)), dimod.SPIN, energy=5)
>>> print(sampleset)
   0  1  2  3  4 energy num_oc.
0 +1 +1 +1 +1 +1      5       1
1 +1 +1 +1 +1 +1      5       1
2 +1 +1 +1 +1 +1      5       1
3 +1 +1 +1 +1 +1      5       1
4 +1 +1 +1 +1 +1      5       1
['SPIN', 5 rows, 5 samples, 5 variables]
>>> print(sampleset.truncate(2))
   0  1  2  3  4 energy num_oc.
0 +1 +1 +1 +1 +1      5       1
1 +1 +1 +1 +1 +1      5       1
['SPIN', 2 rows, 2 samples, 5 variables]
See:

SampleSet.slice()