{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "xp.where(cond, f1(*args), f2(*args))"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " requires explicitly evaluating "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "f1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " even when "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "cond"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is False, and "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "f2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " when cond is True. This function evaluates each function only for their matching condition, if the backend allows for it."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "On Dask, "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "f1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "f2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are applied to the individual chunks and should use functions from the namespace of the chunks."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "",
              "annotation": "Array",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An array with elements from the output of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "f1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " where "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "cond"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is True and either the output of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "f2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "fill_value"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " where "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "cond"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is False. The returned array has data type determined by type promotion rules between the output of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "f1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and either "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "fill_value"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or the output of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "f2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Run one of two elementwise functions depending on a condition."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "cond",
              "annotation": "array",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The condition, expressed as a boolean array."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "args",
              "annotation": "Array or tuple of Arrays",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Argument(s) to "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "f1"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "f2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "). Must be broadcastable with "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "cond"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "f1",
              "annotation": "callable",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Elementwise function of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "args"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", returning a single array. Where "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "cond"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is True, output will be "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f1(arg0[cond], arg1[cond], ...)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "f2",
              "annotation": "callable, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Elementwise function of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "args"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", returning a single array. Where "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "cond"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is False, output will be "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f2(arg0[cond], arg1[cond], ...)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Mutually exclusive with "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "fill_value"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "fill_value",
              "annotation": "Array or scalar, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If provided, value with which to fill output array where "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "cond"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is False. It does not need to be scalar; it needs however to be broadcastable with "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "cond"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "args"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Mutually exclusive with "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "f2"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". You must provide one or the other."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "xp",
              "annotation": "array_namespace, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The standard-compatible namespace for "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "cond"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "args"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Default: infer."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Equivalent to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "f1(*args) if cond else fill_value"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " performed elementwise when "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "fill_value"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is defined, otherwise to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "f1(*args) if cond else f2(*args)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/_lib/array_api_extra/_lib/_funcs.py",
  "item_line": 60,
  "item_type": "function",
  "aliases": [
    "scipy.differentiate.xpx.apply_where"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import array_api_strict as xp\nimport array_api_extra as xpx\na = xp.asarray([5, 4, 3])\nb = xp.asarray([0, 2, 2])\n",
        "execution_status": "unexpected_exception"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "def f(a, b):\n    return a // b\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "xpx.apply_where(b != 0, (a, b), f, fill_value=xp.nan)\n",
        "execution_status": "unexpected_exception"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "cond",
        "annotation": "Array",
        "kind": "POSITIONAL_ONLY",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "args",
        "annotation": "Array | tuple[Array, ...]",
        "kind": "POSITIONAL_ONLY",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "f1",
        "annotation": "Callable[..., Array]",
        "kind": "POSITIONAL_ONLY",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "f2",
        "annotation": "Callable[..., Array] | None",
        "kind": "POSITIONAL_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "fill_value",
        "annotation": "Array | complex | None",
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "xp",
        "annotation": "ModuleType | None",
        "kind": "KEYWORD_ONLY",
        "default": "None"
      }
    ],
    "return_annotation": "Array",
    "target_name": "apply_where"
  },
  "references": null,
  "qa": "scipy._lib.array_api_extra._lib._funcs:apply_where",
  "arbitrary": [],
  "local_refs": [
    "args",
    "cond",
    "f1",
    "f2",
    "fill_value",
    "xp"
  ]
}