{"record":{"id":"39a67d1ca64068a2","repo":"jax-ml/jax","slug":"the-out-argument-to-jnp-mean-is-not-supported","errorCode":null,"errorMessage":"The 'out' argument to jnp.mean is not supported.","messagePattern":"The 'out' argument to jnp\\.mean is not supported\\.","errorType":"validation","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/reductions.py","lineNumber":901,"sourceCode":"    if axis is None:\n      count = core.dimension_as_value(np.size(a))\n    else:\n      count = core.dimension_as_value(_axis_size(a, axis))\n    count = lax.convert_element_type(count, dtype)\n  else:\n    count = sum(_broadcast_to(where, np.shape(a)), axis, dtype=dtype, keepdims=keepdims)\n  return count\n\n@api.jit(static_argnames=('axis', 'dtype', 'keepdims', 'upcast_f16_for_computation'),\n         inline=True)\ndef _mean(a: ArrayLike, axis: Axis = None, dtype: DTypeLike | None = None,\n          out: None = None, keepdims: bool = False, *,\n          upcast_f16_for_computation: bool = True,\n          where: ArrayLike | None = None) -> Array:\n  a = ensure_arraylike(\"mean\", a)\n  where = check_where(\"mean\", where)\n  if out is not None:\n    raise NotImplementedError(\"The 'out' argument to jnp.mean is not supported.\")\n\n  if dtype is None:\n    result_dtype = dtypes.to_inexact_dtype(a.dtype)\n  else:\n    result_dtype = dtypes.check_and_canonicalize_user_dtype(dtype, \"mean\")\n\n  if upcast_f16_for_computation and dtypes.issubdtype(result_dtype, np.inexact):\n    computation_dtype = _upcast_f16(result_dtype)\n  else:\n    computation_dtype = result_dtype\n\n  normalizer = _count(\n      a,\n      axis=axis,\n      keepdims=keepdims,\n      where=where,\n      dtype=computation_dtype,\n  )","sourceCodeStart":883,"sourceCodeEnd":919,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/reductions.py#L883-L919","documentation":"jnp.mean does not support the numpy 'out' in-place output parameter because JAX arrays are immutable. out=None is accepted purely for API compatibility.","triggerScenarios":"jnp.mean(x, out=buf), np.mean(jax_array, out=...) (numpy delegates to the array's .mean method), or x.mean(out=buf) on a JAX array.","commonSituations":"Accumulator-style loops written for numpy that write means into preallocated arrays; generic stat-computation helpers forwarding kwargs.","solutions":["Use the return value: m = jnp.mean(x, axis=0)","For buffer updates under jit: buf = buf.at[i].set(jnp.mean(x))"],"exampleFix":"// before\njnp.mean(x, axis=0, out=means)\n// after\nmeans = jnp.mean(x, axis=0)","handlingStrategy":"validation","validationCode":"means = jnp.mean(x, axis=0)  # never pass out","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Replace accumulator patterns with .at[].set() under jit"],"tags":["jax","mean","out-parameter"],"backgroundTag":"unsupported-out-parameter","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}