qrisp.QuantumArray.__mul__#

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

Performs element-wise multiplication.

Parameters:
otherQuantumArray | QuantumVariable | ArrayLike

The array or scalar to be multiplied. 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.

Returns:
QuantumArray

A new QuantumArray containing the element-wise product. If a QuantumArray or QuantumVariable is provided, the qtype of the output will be determined by the qtypes of the two input objects to prevent overflow. If a classical scalar or numpy array is provided, 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 multiplication.

ValueError

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

NotImplementedError

If qtype of self is not QuantumModulus and other is a classical scalar or numpy array, since quantum-classical multiplication is not supported in this case.

Examples

Multiplying two QuantumArrays of QuantumFloats element-wise:

>>> import numpy as np
>>> from qrisp import QuantumArray, QuantumFloat
>>> a_array = QuantumArray(QuantumFloat(2), shape=(2,2))
>>> b_array = QuantumArray(QuantumFloat(2), shape=(2,2))
>>> a_array[:] = np.eye(2)
>>> b_array[:] = np.eye(2)
>>> r_array = a_array * b_array
>>> print(r_array)
# {OutcomeArray([[1, 0], [0, 1]]): 1.0}