dimod.Response.relabel_variables¶
-
Response.relabel_variables(mapping, inplace=True)[source]¶ Relabel a response’s variables as per a given mapping.
Parameters: Returns: Response with relabeled variables. If inplace=True, returns itself.
Return type: Examples
This example relabels the response of the dimod package’s ExactSolver sampler and saves it as a new response.
>>> import dimod >>> response = dimod.ExactSolver().sample_ising({'a': -0.5, 'b': 1.0}, {('a', 'b'): -1}) >>> new_response = response.relabel_variables({'a': 0, 'b': 1}, inplace=False) >>> [next(new_response.samples())[x] for x in [0, 1]] [-1, -1]
This example code snippet relabels variables in a response.
response = dimod.Response.from_dicts([{'a': -1}, {'a': +1}], {'energy': [-1, 1]}) response.relabel_variables({'a': 0})