dimod.append_variables#

append_variables(sampleset, samples_like, sort_labels=True)[source]#

Create a new SampleSet with the given variables and values.

Not defined for empty sample sets. If sample_like is a SampleSet, its data vectors and info are ignored.

Parameters:
  • sampleset (SampleSet) – SampleSet to build from.

  • samples_like – Samples to add to the sample set. Either a single sample or identical in length to the sample set. ‘samples_like’ is an extension of NumPy’s array_like. See as_samples().

  • sort_labels (bool, optional, default=True) – Return SampleSet.variables in sorted order. For mixed (unsortable) types, the given order is maintained.

Returns:

New sample set with the variables/values added.

Return type:

SampleSet

Examples

>>> sampleset = dimod.SampleSet.from_samples([{'a': -1, 'b': +1},
...                                           {'a': +1, 'b': +1}],
...                                          dimod.SPIN,
...                                          energy=[-1.0, 1.0])
>>> new = dimod.append_variables(sampleset, {'c': -1})
>>> print(new)
   a  b  c energy num_oc.
0 -1 +1 -1   -1.0       1
1 +1 +1 -1    1.0       1
['SPIN', 2 rows, 2 samples, 3 variables]

Add variables from another sample set to the previous example. Note that the energies remain unchanged.

>>> another = dimod.SampleSet.from_samples([{'c': -1, 'd': +1},
...                                         {'c': +1, 'd': +1}],
...                                        dimod.SPIN,
...                                        energy=[-2.0, 1.0])
>>> new = dimod.append_variables(sampleset, another)
>>> print(new)
   a  b  c  d energy num_oc.
0 -1 +1 -1 +1   -1.0       1
1 +1 +1 +1 +1    1.0       1
['SPIN', 2 rows, 2 samples, 4 variables]