View source on GitHub |
Takes the partial trace of a given tensor.
cirq.partial_trace(
tensor: np.ndarray, keep_indices: Sequence[int]
) -> np.ndarray
The input tensor must have shape (d_0, ..., d_{k-1}, d_0, ..., d_{k-1})
.
The trace is done over all indices that are not in keep_indices. The
resulting tensor has shape (d_{i_0}, ..., d_{i_r}, d_{i_0}, ..., d_{i_r})
where i_j
is the j
th element of keep_indices
.
Raises | |
---|---|
ValueError
|
if the tensor is not of the correct shape or the indices are not from the first half of valid indices for the tensor. |