dimod.binary.BinaryArray

BinaryArray(labels: Union[int, Iterable[Hashable]], dtype: Union[numpy.dtype, None, type, numpy.typing._dtype_like._SupportsDType[numpy.dtype], str, Tuple[Any, int], Tuple[Any, Union[typing_extensions.SupportsIndex, Sequence[typing_extensions.SupportsIndex]]], List[Any], numpy.typing._dtype_like._DTypeDict, Tuple[Any, Any]] = None) numpy.ndarray[source]

Return a NumPy array of binary quadratic models, each with a single binary variable.

Parameters
  • labels – Either an iterable of variable labels or the number of required models. If a number, labels are generated using uuid.UUID.

  • dtype – Data type for the returned binary quadratic models.

Returns

Array of BinaryQuadraticModels, each representing a single binary variable.

Examples

This example generates the QUBO, \({x}^{T} {Q}{x}\), for a Boolean AND gate from the QUBO coefficients matrix,

\[\begin{split}Q = \begin{bmatrix} 0 & 1 & -2 \\ 0 & 0 & -2 \\ 0 & 0 & 3 \end{bmatrix},\end{split}\]

derived in the Ocean documentation’s AND example.

>>> Q = [[0, 1, -2], [0, 0, -2], [0, 0, 3]]
>>> x = dimod.BinaryArray(["in1", "in2", "out"])
>>> bqm = x.dot(Q).dot(x)
>>> print(bqm.to_polystring())
3*out + in1*in2 - 2*in1*out - 2*in2*out