dq.where
where(condition: ArrayLike, x: QArrayLike, y: QArrayLike) -> QArray
Select values from two qarrays depending on a condition.
Parameters:
-
condition(array-like of shape (...)) –Boolean condition, broadcast against the shapes of
xandy. -
x(qarray-like of shape (..., n, m)) –Values selected when
conditionis true. -
y(qarray-like of shape (..., n, m)) –Values selected when
conditionis false.
Returns:
-
(qarray of shape (..., n, m))
–
Qarray with values chosen from
xandy.
Raises:
-
TypeError–If neither
xnoryis a qarray, in which casejax.numpy.where()should be used directly.
Examples:
>>> condition = jnp.array([True, False])[:, None, None]
>>> dq.where(condition, dq.fock(2, 0), dq.fock(2, 1))
QArray: shape=(2, 2, 1), dims=(2,), dtype=complex64, layout=dense
[[[1.+0.j]
[0.+0.j]]
[[0.+0.j]
[1.+0.j]]]