outer_product
Graph.outer_product(x, y, *, name=None)
Calculate the outer product of two vectors.
The vectors can have different last dimensions but must have broadcastable batch dimensions.
Parameters
- x (np.ndarray or Tensor) – The left multiplicand. It must be a vector of shape
(..., M)
. - y (np.ndarray or Tensor) – The right multiplicand. It must be a vector of shape
(..., N)
. - name (str or None , optional) – The name of the node.
Returns
The outer product of two vectors of shape (..., M, N)
.
Return type
SEE ALSO
Graph.density_matrix_expectation_value
: Expectation value of an operator with respect to a density matrix.
Graph.expectation_value
: Expectation value of an operator with respect to a pure state.
Graph.inner_product
: Inner product of two vectors.
Graph.trace
: Trace of an object.
Notes
The outer product of two complex vectors and is defined as
For more information about the outer product, see outer product on Wikipedia.
Examples
>>> graph.outer_product(np.array([1j, 1j]), np.array([1j, -1j]), name="outer")
<Tensor: name="outer", operation_name="outer_product", shape=(2, 2)>
>>> result = bo.execute_graph(graph=graph, output_node_names="outer")
>>> result["output"]["outer"]["value"]
array([[1.+0.j, -1.+0.j], [1.+0.j, -1.+0.j]])
>>> graph.outer_product(np.ones((3,1,2), np.ones(2,2), name="outer2")
<Tensor: name="outer2", operation_name="outer_product", shape=(3, 2, 2, 2)>
>>> result = bo.execute_graph(graph=graph, output_node_names="outer2")
>>> result["output"]["outer2"]["value"]
array([[[[1, 1], [1, 1]], [[1, 1], [1, 1]]],
[[[1, 1], [1, 1]], [[1, 1], [1, 1]]],
[[[1, 1], [1, 1]], [[1, 1], [1, 1]]])