dimod.append_data_vectors#

append_data_vectors(sampleset, **vectors)[source]#

Create a new SampleSet with additional fields in SampleSet.record.

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

  • **vectors (list) – Per-sample data to be appended to SampleSet.record. Each keyword is a new field name and each keyword parameter should be a list of scalar values or numpy arrays (lists and tuples will be converted to numpy arrays).

Returns:

SampleSet

Return type:

SampleSet

Examples

The following example appends a field of lists to SampleSet.record.

>>> sampleset = dimod.SampleSet.from_samples([[-1,  1], [-1,  1]], energy=[-1.4, -1.4], vartype='SPIN')
>>> print(sampleset)
   0  1 energy num_oc.
0 -1 +1   -1.4       1
1 -1 +1   -1.4       1
['SPIN', 2 rows, 2 samples, 2 variables]
>>> sampleset = dimod.append_data_vectors(sampleset, new=[[0, 1], [1, 2]])
>>> print(sampleset)
   0  1 energy num_oc.   new
0 -1 +1   -1.4       1 [0 1]
1 -1 +1   -1.4       1 [1 2]
['SPIN', 2 rows, 2 samples, 2 variables]
>>> print(sampleset.record.dtype)
(numpy.record, [('sample', 'i1', (2,)), ('energy', '<f8'), ('num_occurrences', '<i8'), ('new', '<i8', (2,))])