pyqubo.Array.subtract

Array.subtract(other)[source]

Returns a difference between other and self.

Parameters:other (Array/ndarray/int/float) – Subtrahend.
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.subtract(array_b)
Array([[(Binary(a)+(Binary(d)*Num(-1))), (Binary(b)+Num(-1))],
       [(Binary(c)+(Binary(f)*Num(-1))), ((Binary(g)*Num(-1))+Num(2))]])
>>> array_a - array_b
Array([[(Binary(a)+(Binary(d)*Num(-1))), (Binary(b)+Num(-1))],
       [(Binary(c)+(Binary(f)*Num(-1))), ((Binary(g)*Num(-1))+Num(2))]])

Difference of self and scalar value.

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

Difference 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)), -2]])