qrisp.QuantumArray.__iadd__#

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

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

Parameters:
otherQuantumArray | QuantumVariable | ArrayLike

The array or scalar to be added to 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 added to each element of the QuantumArray.

Returns:
QuantumArray

The modified QuantumArray containing the result of the in-place addition. 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 addition.

ValueError

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

Examples

Adding a scalar to a QuantumArray of QuantumFloats, and adding two QuantumArrays:

>>> import numpy as np
>>> from qrisp import QuantumArray, QuantumFloat
>>> qa = QuantumArray(QuantumFloat(8,-1), shape=(2,2))
>>> qa[:] = np.array([[1.0, 2.0], [3.0, 4.0]])
>>> qa += 1.0
>>> print(qa)  # Output: [[2.0, 3.0], [4.0, 5.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: [[2.5, 4.5], [6.5, 8.5]]