dimod.DiscreteQuadraticModel.from_numpy_vectors

classmethod DiscreteQuadraticModel.from_numpy_vectors(case_starts, linear_biases, quadratic, labels=None)[source]

Construct a DQM from five numpy vectors.

Parameters
  • case_starts (array-like) – A length num_variables() array. The cases associated with variable v are in the range [case_starts[v], cases_starts[v+1]).

  • linear_biases (array-like) – A length num_cases() array. The linear biases.

  • quadratic (tuple) –

    A three tuple containing:

    • irow: A length num_interactions() array. If the case interactions were defined in a sparse matrix, these would be the row indices.

    • icol: A length num_interactions() array. If the case interactions were defined in a sparse matrix, these would be the column indices.

    • quadratic_biases: A length num_interactions() array. If the case interactions were defined in a sparse matrix, these would be the values.

  • labels (list, optional) – The variable labels. Defaults to index-labeled.

Example

>>> dqm = dimod.DiscreteQuadraticModel()
>>> u = dqm.add_variable(5)
>>> v = dqm.add_variable(3, label='3var')
>>> dqm.set_quadratic(u, v, {(0, 2): 1})
>>> vectors = dqm.to_numpy_vectors()
>>> new = dimod.DiscreteQuadraticModel.from_numpy_vectors(*vectors)