qrisp.QuantumArray.__isub__#

QuantumArray.__isub__(other: QuantumArray | QuantumVariable | 'ArrayLike') QuantumArray[source]#

Performs element-wise in-place subtraction. Note that this modifies the original QuantumArray and does not create a new one.

Parameters:
otherQuantumArray | QuantumVariable | ArrayLike

The array or scalar to be subtracted from the QuantumArray. If an array is provided, it must have the same shape as the original QuantumArray. If a scalar is provided, it will be subtracted from each element of the QuantumArray.

Returns:
QuantumArray

The modified QuantumArray containing the result of the in-place subtraction. The qtype of the output will be the same as the qtype of self. This may lead to overflow.

Raises:
TypeError

If the qtypes of self and other are incompatible for subtraction.

ValueError

If other is an array (QuantumArray or numpy/jax array) and its shape does not match the shape of self.

Examples

Subtracting a scalar from a QuantumArray of QuantumFloats, and subtracting two QuantumArrays:

>>> import numpy as np
>>> from qrisp import QuantumArray, QuantumFloat
>>> qa = QuantumArray(QuantumFloat(8,-1,signed=True), shape=(2,2))
>>> qa[:] = np.array([[1.0, 2.0], [3.0, 4.0]])
>>> qa -= 1.0
>>> print(qa)  # Output: [[0.0, 1.0], [2.0, 3.0]]
>>> qb = QuantumArray(QuantumFloat(4,-1), shape=(2,2))
>>> qb[:] = np.array([[0.5, 1.5], [2.5, 3.5]])
>>> qa -= qb
>>> print(qa)  # Output: [[-0.5, -0.5], [-0.5, -0.5]]