# inner_product

Graph.inner_product(x, y, *, name=None)

Calculate the inner product of two vectors.

The vectors must have the same last dimension and broadcastable shapes.

Parameters:
• x (np.ndarray or Tensor) – The left multiplicand. It must be a vector of shape (..., D).

• y (np.ndarray or Tensor) – The right multiplicand. It must be a vector of shape (..., D).

• name (str or None, optional) – The name of the node.

Returns:

The inner product of two vectors of shape (...).

Return type:

Tensor

density_matrix_expectation_value

Expectation value of an operator with respect to a density matrix.

einsum

Tensor contraction via Einstein summation convention.

expectation_value

Expectation value of an operator with respect to a pure state.

outer_product

Outer product of two vectors.

trace

Trace of an object.

Notes

The inner product or dot product of two complex vectors $$\mathbf{x}$$ and $$\mathbf{y}$$ is defined as

$\langle \mathbf{x} \vert \mathbf{y} \rangle = \sum_i x^\ast_{i} y_{i} .$

Examples

>>> graph.inner_product(np.array([1j, 1j]), np.array([1j, 1j]), name="inner")
<Tensor: name="inner", operation_name="inner_product", shape=()>
>>> result = qctrl.functions.calculate_graph(graph=graph, output_node_names=["inner"])
>>> result.output["inner"]["value"]
2.+0.j

>>> graph.inner_product(np.ones((3,1,4), np.ones(2,4), name="inner")
<Tensor: name="inner", operation_name="inner_product", shape=(3, 2)>
>>> result = qctrl.functions.calculate_graph(graph=graph, output_node_names=["inner"])
>>> result.output["inner"]["value"]
array([[4, 4], [4, 4], [4, 4]])