# qml.dot¶

dot(coeffs, ops, pauli=False)[source]

Returns the dot product between the coeffs vector and the ops list of operators.

This function returns the following linear combination: $$\sum_{k} c_k O_k$$, where $$c_k$$ and $$O_k$$ are the elements inside the coeffs and ops arguments, respectively.

Parameters
• coeffs (Sequence[float]) – sequence containing the coefficients of the linear combination

• ops (Sequence[Operator]) – sequence containing the operators of the linear combination

• pauli (bool, optional) – If True, a PauliSentence operator is used to represent the linear combination. If False, a Sum operator is returned. Defaults to False.

Raises

ValueError – if the number of coefficients and operators does not match or if they are empty

Returns

operator describing the linear combination

Return type

Example

>>> coeffs = np.array([1.1, 2.2])
>>> ops = [qml.PauliX(0), qml.PauliY(0)]
>>> qml.dot(coeffs, ops)
(1.1*(PauliX(wires=))) + (2.2*(PauliY(wires=)))
>>> qml.dot(coeffs, ops, pauli=True)
1.1 * X(0)
+ 2.2 * Y(0)


pauli=True can be used to construct a more efficient, simplified version of the operator. Note that it returns a PauliSentence, which is not an Operator. This specialized representation can be converted to an operator:

>>> qml.dot([1, 2], [qml.PauliX(0), qml.PauliX(0)], pauli=True).operation()
3.0*(PauliX(wires=))


Using pauli=True and then converting the result to an Operator is much faster than using pauli=False, but it only works for pauli words (see is_pauli_word()).