dimod.binary.BinaryArray#

BinaryArray(labels: int | Iterable[Hashable], dtype: dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any] = None) 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