qrisp.QuantumArray.__imul__#
- QuantumArray.__imul__(other: ArrayLike) QuantumArray[source]#
Performs element-wise in-place multiplication. Note that this modifies the original QuantumArray and does not create a new one.
- Parameters:
- otherArrayLike
The array or scalar to be multiplied with 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 multiplied with each element of the QuantumArray. If the
qtypeof self is an unsigned QuantumFloat, the right-hand side must be non-negative.
- Returns:
- QuantumArray
The modified QuantumArray containing the result of the in-place multiplication. The
qtypeof the output will be the same as theqtypeof self. This may lead to overflow.
- Raises:
- TypeError
If the qtypes of self and other are incompatible for multiplication.
- ValueError
If other is an array (QuantumArray or numpy/jax array) and its shape does not match the shape of self.
- TypeError
If other is a QuantumArray or QuantumVariable, since quantum-quantum in-place multiplication is not supported. Use out-of-place multiplication instead.
- NotImplementedError
If in tracing mode and self’s
qtypeis not QuantumModulus, since quantum-classical in-place multiplication is not supported in tracing mode for non-QuantumModulus types.
Examples
Multiplying a scalar with a QuantumArray of QuantumFloats, and scaling a QuantumArray by a numpy array:
>>> 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 *= 2.0 >>> print(qa) # Output: [[2.0, 4.0], [6.0, 8.0]] >>> qa *= np.array([[0.5, 1.5], [2.5, 3.5]]) >>> print(qa) # Output: [[1.0, 6.0], [15.0, 28.0]]