Skip to content

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 x and y.

  • x (qarray-like of shape (..., n, m)) –

    Values selected when condition is true.

  • y (qarray-like of shape (..., n, m)) –

    Values selected when condition is false.

Returns:

  • (qarray of shape (..., n, m)) –

    Qarray with values chosen from x and y.

Raises:

  • TypeError –

    If neither x nor y is a qarray, in which case jax.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]]]