dimod.SampleSet.append_variables¶
-
SampleSet.append_variables(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: - 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.variablesin sorted order. For mixed (unsortable) types, the given order is maintained.
Returns: New sample set with the variables/values added.
Return type: Examples
>>> sampleset = dimod.SampleSet.from_samples([{'a': -1, 'b': +1}, ... {'a': +1, 'b': +1}], ... dimod.SPIN, ... energy=[-1.0, 1.0]) >>> new = sampleset.append_variables({'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 = sampleset.append_variables(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]
- 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