dimod.BinaryQuadraticModel.from_numpy_vectors

classmethod BinaryQuadraticModel.from_numpy_vectors(linear, quadratic, offset, vartype, variable_order=None)[source]

Create a binary quadratic model from vectors.

Parameters:
  • linear (array_like) – A 1D array-like iterable of linear biases.
  • quadratic (tuple[array_like, array_like, array_like]) – A 3-tuple of 1D array_like vectors of the form (row, col, bias).
  • offset (numeric, optional) – Constant offset for the binary quadratic model.
  • vartype (Vartype/str/set) –

    Variable type for the binary quadratic model. Accepted input values:

    • Vartype.SPIN, 'SPIN', {-1, 1}
    • Vartype.BINARY, 'BINARY', {0, 1}
  • variable_order (iterable, optional) – If provided, labels the variables; otherwise, indices are used.
Returns:

BinaryQuadraticModel

Examples

>>> import dimod
>>> import numpy as np
...
>>> linear_vector = np.asarray([-1, 1])
>>> quadratic_vectors = (np.asarray([0]), np.asarray([1]), np.asarray([-1.0]))
>>> bqm = dimod.BinaryQuadraticModel.from_numpy_vectors(linear_vector, quadratic_vectors, 0.0, dimod.SPIN)
>>> print(bqm.quadratic)
{(0, 1): -1.0}