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
SEE ALSO
Graph.density_matrix_expectation_value
: Expectation value of an operator with respect to a density matrix.
Graph.einsum
: Tensor contraction via Einstein summation convention.
Graph.expectation_value
: Expectation value of an operator with respect to a pure state.
Graph.outer_product
: Outer product of two vectors.
Graph.trace
: Trace of an object.
Notes
The inner product or dot product of two complex vectors x and y is defined as
⟨x∣y⟩=i∑xi∗yi.For more information about the inner product, see dot product on Wikipedia.
Examples
>>> graph.inner_product(np.array([1j, 1j]), np.array([1j, 1j]), name="inner")
<Tensor: name="inner", operation_name="inner_product", shape=()>
>>> result = bo.execute_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="inner2")
<Tensor: name="inner2", operation_name="inner_product", shape=(3, 2)>
>>> result = bo.execute_graph(graph=graph, output_node_names="inner2")
>>> result["output"]["inner2"]["value"]
array([[4, 4], [4, 4], [4, 4]])