# 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, optional) – The name of the node.

Returns

The outer product of two vectors of shape (..., M, N).

Return type

Tensor

expectation_value()

Expectation value of an operator with respect to a state.

inner_product()

Inner product of two vectors.

trace()

Trace of an object.

Notes

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

$(\mathbf{x} \otimes \mathbf{y})_{ij} = x_{i} y^\ast_{j}.$

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 = qctrl.functions.calculate_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="outer")
<Tensor: name="outer", operation_name="outer_product", shape=(3, 2, 2, 2)>
>>> result = qctrl.functions.calculate_graph(graph=graph, output_node_names=["outer"])
>>> result.output["outer"]["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]]])