dimod.binary.BinaryQuadraticModel.reduce_linear#

BinaryQuadraticModel.reduce_linear(function: Callable, initializer: float | floating | integer | None = None) Any[source]#

Apply function of two arguments cumulatively to the linear biases.

See functools.reduce() for information on reducing an iterable to a single value.

Parameters:
  • function – Function of two arguments to apply cumulatively to linear biases.

  • initializer – A value to precede the linear biases.

Examples

>>> from operator import add
>>> bqm = dimod.BinaryQuadraticModel({0: 1, 1: 2, 2: 3},
...                                  {(0, 1): 5},
...                                  0, "BINARY")
>>> bqm.reduce_linear(add)
6.0