pyqubo.Array.add

Array.add(other)[source]

Returns a sum of self and other.

Parameters:other (Array/ndarray/int/float) – Addend.
Returns:Array

Example

>>> from pyqubo import Array, Binary
>>> import numpy as np
>>> array_a = Array([[Binary('a'), Binary('b')], [Binary('c'), 2]])
>>> array_b = Array([[Binary('d'), 1], [Binary('f'), Binary('g')]])
>>> array_a.add(array_b)
Array([[(Binary(a)+Binary(d)), (Binary(b)+Num(1))],
       [(Binary(c)+Binary(f)), (Binary(g)+Num(2))]])
>>> array_a + array_b
Array([[(Binary(a)+Binary(d)), (Binary(b)+Num(1))],
       [(Binary(c)+Binary(f)), (Binary(g)+Num(2))]])

Sum of self and scalar value.

>>> array_a + 5
Array([[(Binary(a)+Num(5)), (Binary(b)+Num(5))],
       [(Binary(c)+Num(5)), 7]])

Sum of self and numpy ndarray.

>>> array_a + np.array([[1, 2], [3, 4]])
Array([[(Binary(a)+Num(1)), (Binary(b)+Num(2))],
       [(Binary(c)+Num(3)), 6]])