{"record":{"id":"4152c54dddd06e13","repo":"jax-ml/jax","slug":"either-both-or-neither-of-the-x-and-y-arguments-sh","errorCode":null,"errorMessage":"Either both or neither of the x and y arguments should be provided to jax.numpy.where, got {x} and {y}.","messagePattern":"Either both or neither of the x and y arguments should be provided to jax\\.numpy\\.where, got (.+?) and (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":2801,"sourceCode":"    >>> jnp.nonzero(x > 4)\n    (Array([5, 6, 7, 8, 9], dtype=int32),)\n\n    When ``x`` and ``y`` are provided, ``where`` selects between them based on\n    the specified condition:\n\n    >>> jnp.where(x > 4, x, 0)\n    Array([0, 0, 0, 0, 0, 5, 6, 7, 8, 9], dtype=int32)\n  \"\"\"\n  if x is None and y is None:\n    util.check_arraylike(\"where\", condition)\n    return nonzero(condition, size=size, fill_value=fill_value)\n  else:\n    util.check_arraylike(\"where\", condition, x, y)\n    if size is not None or fill_value is not None:\n      raise ValueError(\"size and fill_value arguments cannot be used in \"\n                       \"three-term where function.\")\n    if x is None or y is None:\n      raise ValueError(\"Either both or neither of the x and y arguments \"\n                       \"should be provided to jax.numpy.where, got \"\n                       f\"{x} and {y}.\")\n    return util._where(condition, x, y)\n\n\n@export\ndef select(\n    condlist: Sequence[ArrayLike],\n    choicelist: Sequence[ArrayLike],\n    default: ArrayLike = 0,\n) -> Array:\n  \"\"\"Select values based on a series of conditions.\n\n  JAX implementation of :func:`numpy.select`, implemented in terms\n  of :func:`jax.lax.select_n`\n\n  Args:\n    condlist: sequence of array-like conditions. All entries must be mutually","sourceCodeStart":2783,"sourceCodeEnd":2819,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L2783-L2819","documentation":"jnp.where requires either only condition (one-arg form) or both x and y (three-arg form). Passing exactly one of x or y is ambiguous and rejected.","triggerScenarios":"Calling jnp.where(cond, x) or jnp.where(cond, y=0) where the other branch is omitted (e.g. left as default None).","commonSituations":"Coming from APIs where the else branch defaults to 0 or False; partial refactors that delete one branch; kwargs confusion where x is passed but y forgotten.","solutions":["Supply both x and y: jnp.where(cond, x, 0)","Or drop both to use the index form: jnp.where(cond)"],"exampleFix":"// before\njnp.where(cond, x)\n// after\njnp.where(cond, x, 0)","handlingStrategy":"validation","validationCode":"if (x is None) != (y is None):\n    y = 0 if y is None else y  # or raise","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default both branches explicitly in wrappers: x = 0 if x is None else x","Lint for where calls with exactly two positional args"],"tags":["jax","where","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}