dimod.SampleSet.filter#

SampleSet.filter(pred: Callable[[Any], bool]) SampleSet[source]#

Return a new sampleset with rows filtered by the given predicate.

Parameters:

pred – A function that accepts a named tuple as returned by data() and returns a bool.

Returns:

A new sample set with only the data rows for which pred returns True.

Examples

>>> sampleset = dimod.SampleSet.from_samples(
...     [{'a': 1, 'b': 0}, {'a': 0, 'b': 1}],
...     vartype=dimod.BINARY,
...     energy=[0, 1],
...     is_feasible=[True, False]
...     )
>>> feasible_sampleset = sampleset.filter(lambda d: d.is_feasible)
>>> print(feasible_sampleset)
   a  b energy num_oc. is_fea.
0  1  0      0       1    True
['BINARY', 1 rows, 1 samples, 2 variables]