dimod.binary.BinaryQuadraticModel.add_quadratic_from_dense#
- BinaryQuadraticModel.add_quadratic_from_dense(quadratic: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])[source]#
Add quadratic biases from a square 2d array-like.
- Parameters:
quadratic – Quadratic biases as a square 2d array_like.
- Raises:
ValueError – If any self-loops are given; i.e., the array contains a non-zero value on its diagonal, which would set a bias for interaction
(u, u)
.
Examples
>>> bqm = dimod.BinaryQuadraticModel("BINARY") >>> bqm.add_quadratic_from_dense([[0, -0.4, 0.2],[0, 0, 0], [0, 0, 0]]) >>> print(bqm) BinaryQuadraticModel({0: 0.0, 1: 0.0, 2: 0.0}, {(1, 0): -0.4, (2, 0): 0.2}, 0.0, 'BINARY')