dimod.BinaryQuadraticModel.to_numpy_vectors

BinaryQuadraticModel.to_numpy_vectors(variable_order=None, dtype=<type 'float'>, index_dtype=<type 'numpy.int64'>, sort_indices=False)[source]

Convert a binary quadratic model to numpy arrays.

Parameters:
  • variable_order (iterable, optional) – If provided, labels the variables; otherwise, row/column indices are used.
  • dtype (numpy.dtype, optional) – Data-type of the biases. By default, the data-type is inferred from the biases.
  • index_dtype (numpy.dtype, optional) – Data-type of the indices. By default, the data-type is inferred from the labels.
  • sort_indices (bool, optional, default=False) – If True, the indices are sorted, first by row then by column. Otherwise they match quadratic.
Returns:

A numpy array of the linear biases.

tuple: The quadratic biases in COOrdinate format.

ndarray: A numpy array of the row indices of the quadratic matrix entries

ndarray: A numpy array of the column indices of the quadratic matrix entries

ndarray: A numpy array of the values of the quadratic matrix entries

The offset

Return type:

ndarray

Examples

>>> bqm = dimod.BinaryQuadraticModel({}, {(0, 1): .5, (3, 2): -1, (0, 3): 1.5}, 0.0, dimod.SPIN)
>>> lin, (i, j, vals), off = bqm.to_numpy_vectors(sort_indices=True)
>>> lin
array([0., 0., 0., 0.])
>>> i
array([0, 0, 2])
>>> j
array([1, 3, 3])
>>> vals
array([ 0.5,  1.5, -1. ])