qml.math.marginal_prob

marginal_prob(prob, axis)[source]

Compute the marginal probability given a joint probability distribution expressed as a tensor. Each random variable corresponds to a dimension.

If the distribution arises from a quantum circuit measured in computational basis, each dimension corresponds to a wire. For example, for a 2-qubit quantum circuit prob[0, 1] is the probability of measuring the first qubit in state 0 and the second in state 1.

Parameters
  • prob (tensor_like) – 1D tensor of probabilities. This tensor should of size (2**N,) for some integer value N.

  • axis (list[int]) – the axis for which to calculate the marginal probability distribution

Returns

the marginal probabilities, of size (2**len(axis),)

Return type

tensor_like

Example

>>> x = tf.Variable([1, 0, 0, 1.], dtype=tf.float64) / np.sqrt(2)
>>> marginal_prob(x, axis=[0, 1])
<tf.Tensor: shape=(4,), dtype=float64, numpy=array([0.70710678, 0.        , 0.        , 0.70710678])>
>>> marginal_prob(x, axis=[0])
<tf.Tensor: shape=(2,), dtype=float64, numpy=array([0.70710678, 0.70710678])>

Contents

Using PennyLane

Release news

Development

API

Internals