cirq.partial_trace
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
.
Args |
tensor
|
The tensor to sum over. This tensor must have a shape
(d_0, ..., d_{k-1}, d_0, ..., d_{k-1}) .
|
keep_indices
|
Which indices to not sum over. These are only the indices
of the first half of the tensors indices (i.e. all elements must
be between 0 and tensor.ndims / 2 - 1 inclusive).
|
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.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-06-27 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-27 UTC."],[],[]]