dimod.SampleSet.from_samples¶
-
classmethod
SampleSet.from_samples(samples_like, vartype, energy, info=None, num_occurrences=None, aggregate_samples=False, sort_labels=True, **vectors)[source]¶ Build a
SampleSetfrom raw samples.Parameters: - samples_like – A collection of raw samples. ‘samples_like’ is an extension of NumPy’s array_like.
See
as_samples(). - vartype (
Vartype/str/set) –Variable type for the
SampleSet. Accepted input values:Vartype.SPIN,'SPIN',{-1, 1}Vartype.BINARY,'BINARY',{0, 1}
- energy (array_like) – Vector of energies.
- info (dict, optional) – Information about the
SampleSetas a whole formatted as a dict. - num_occurrences (array_like, optional) – Number of occurrences for each sample. If not provided, defaults to a vector of 1s.
- aggregate_samples (bool, optional, default=False) – If True, all samples in returned
SampleSetare unique, with num_occurrences accounting for any duplicate samples in samples_like. - sort_labels (bool, optional, default=True) – Return
SampleSet.variablesin sorted order. For mixed (unsortable) types, the given order is maintained. - **vectors (array_like) – Other per-sample data.
Returns: Examples
This example creates a SampleSet out of a samples_like object (a dict).
>>> import dimod >>> import numpy as np ... >>> dimod.SampleSet.from_samples(dimod.as_samples({'a': 0, 'b': 1, 'c': 0}), ... 'BINARY', 0) # doctest: +SKIP SampleSet(rec.array([([0, 1, 0], 0, 1)], ... dtype=[('sample', 'i1', (3,)), ('energy', '<i4'), ('num_occurrences', '<i4')]), ... ['a', 'b', 'c'], {}, 'BINARY')
- samples_like – A collection of raw samples. ‘samples_like’ is an extension of NumPy’s array_like.
See