qrisp.dot#

dot(a, b, out=None)[source]#

Port of the popular numpy function with similar semantics.

Parameters:
aQuantumArray or QuantumFloat or numpy.ndarray

The first operand.

bQuantumArray or QuantumFloat or numpy.ndarray

The second operand.

outQuantumArray, optional

The QuantumArray to store the output in. The default is None.

Returns:
QuantumArray

The result as described in the numpy documentation.

Examples

We create two QuantumArrays and apply dot as a function performing matrix-vector multiplication.

>>> import numpy as np
>>> from qrisp import QuantumFloat, QuantumArray, dot
>>> qf = QuantumFloat(5,0, signed = False)
>>> q_arr_0 = QuantumArray(qf)
>>> q_arr_1 = QuantumArray(qf)
>>> q_arr_0[:] = [2,3]
>>> q_arr_1[:] = 2*np.eye(2)
>>> res = dot(q_arr_0, q_arr_1)
>>> print(res)
{OutcomeArray([[4, 6]]): 1.0}

Scalar-product:

>>> q_arr_0 = QuantumArray(qf)
>>> q_arr_1 = QuantumArray(qf)
>>> q_arr_0[:] = [3,4,5]
>>> q_arr_1[:] = [1,1,1]
>>> res = dot(q_arr_0, q_arr_1)
>>> print(res)
{12: 1.0}

Matrix-matrix multiplication

>>> qf = QuantumFloat(3,0, signed = True)
>>> q_arr_0 = QuantumArray(qf)
>>> q_arr_1 = QuantumArray(qf)
>>> q_arr_0[:] = [[0,1],[1,0]]
>>> q_arr_1[:] = [[1,0],[0,-1]]
>>> res = dot(q_arr_0, q_arr_1)
>>> print(res)
{OutcomeArray([[ 0, -1],
               [ 1,  0]]): 1.0}