{"record":{"id":"bcab73e32f859cb4","repo":"jax-ml/jax","slug":"the-out-argument-to-jnp-nanmean-is-not-supported","errorCode":null,"errorMessage":"The 'out' argument to jnp.nanmean is not supported.","messagePattern":"The 'out' argument to jnp\\.nanmean is not supported\\.","errorType":"validation","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/reductions.py","lineNumber":1819,"sourceCode":"    ...                    [1, 1, 0, 1]], dtype=bool)\n    >>> jnp.nanmean(x, axis=1, keepdims=True, where=where)\n    Array([[ 3. ],\n           [ 9. ],\n           [-1.5]], dtype=float32)\n\n    If ``where`` is ``False`` at all elements, ``jnp.nanmean`` returns ``nan``\n    along the given axis.\n\n    >>> where = jnp.array([[False],\n    ...                    [False],\n    ...                    [False]])\n    >>> jnp.nanmean(x, axis=0, keepdims=True, where=where)\n    Array([[nan, nan, nan, nan]], dtype=float32)\n  \"\"\"\n  a = ensure_arraylike(\"nanmean\", a)\n  where = check_where(\"nanmean\", where)\n  if out is not None:\n    raise NotImplementedError(\"The 'out' argument to jnp.nanmean is not supported.\")\n  if dtypes.issubdtype(a.dtype, np.bool_) or dtypes.issubdtype(a.dtype, np.integer):\n    return mean(a, axis, dtype, out, keepdims, where=where)\n  if dtype is None:\n    dtype = dtypes.to_inexact_dtype(a.dtype)\n  else:\n    dtype = dtypes.check_and_canonicalize_user_dtype(dtype, \"mean\")\n  nan_mask = lax.bitwise_not(lax._isnan(a))\n  normalizer = sum(nan_mask, axis=axis, dtype=dtype, keepdims=keepdims, where=where)\n  td = lax.div(nansum(a, axis, dtype=dtype, keepdims=keepdims, where=where), normalizer)\n  return td\n\n\n@export\n@api.jit(static_argnames=('axis', 'dtype', 'keepdims'))\ndef nanvar(a: ArrayLike, axis: Axis = None, dtype: DTypeLike | None = None, out: None = None,\n           ddof: int = 0, keepdims: bool = False,\n           where: ArrayLike | None = None, mean: ArrayLike | None = None) -> Array:\n  r\"\"\"Compute the variance of array elements along a given axis, ignoring NaNs.","sourceCodeStart":1801,"sourceCodeEnd":1837,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/reductions.py#L1801-L1837","documentation":"jnp.nanmean does not support the NumPy out= in-place output argument; JAX arrays are immutable so writing into a caller-supplied buffer is impossible. The check fires before any computation.","triggerScenarios":"Calling jnp.nanmean(a, out=buf) or via positional args jnp.nanmean(a, 0, None, True, buf-like).","commonSituations":"Porting NaN-ignoring statistics code from NumPy/SciPy that used out= for memory reuse; kwargs-forwarding wrappers.","solutions":["Drop out and capture the return value","Rewrite buffer-reuse idioms as jitted functions; JIT already optimizes allocations"],"exampleFix":"// before\nnp.nanmean(x, out=result)\n// after\nresult = jnp.nanmean(x)","handlingStrategy":"validation","validationCode":"if out is not None:\n    out = None  # or raise early with your own message\nm = jnp.nanmean(a, axis=axis, dtype=dtype, where=where)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never forward out= to nan* reductions","Document immutability convention for teams coming from NumPy"],"tags":["jax","numpy","nanmean","out-argument"],"backgroundTag":"unsupported-out-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}