|View source on GitHub|
Returns an index corresponding to a desired subset of an np.ndarray.
cirq.linalg.slice_for_qubits_equal_to( target_qubit_axes: Sequence[int], little_endian_qureg_value: int = 0, *, big_endian_qureg_value: int = 0, num_qubits: Optional[int] = None, qid_shape: Optional[Tuple[int, ...]] = None ) -> Tuple[Union[slice, int, 'ellipsis'], ...]
It is assumed that the np.ndarray's shape is of the form (2, 2, 2, ..., 2).
# A '4 qubit' tensor with values from 0 to 15. r = np.array(range(16)).reshape((2,) * 4) # We want to index into the subset where qubit #1 and qubit #3 are ON. s = cirq.slice_for_qubits_equal_to([1, 3], 0b11) print(s) # (slice(None, None, None), 1, slice(None, None, None), 1, Ellipsis) # Get that subset. It corresponds to numbers of the form 0b*1*1. # where here '*' indicates any possible value. print(r[s]) # [[ 5 7] # [13 15]]
||The qubits that are specified by the index bits. All other axes of the slice are unconstrained.|
||An integer whose bits specify what value is desired for of the target qubits. The integer is little endian w.r.t. the target qubit axes, meaning the low bit of the integer determines the desired value of the first targeted qubit, and so forth with the k'th targeted qubit's value set to bool(qureg_value & (1 << k)).|
||If specified the slices will extend all the way up to this number of qubits, otherwise if it is None, the final element return will be Ellipsis. Optional and defaults to using Ellipsis.|
The qid shape of the state vector being sliced. Specify this
|An index object that will slice out a mutable view of the desired subset of a tensor.|