{"record":{"id":"63ad74dc59300eae","repo":"jax-ml/jax","slug":"jax-numpy-arange-arguments-must-be-scalars-got","errorCode":null,"errorMessage":"jax.numpy.arange: arguments must be scalars; got {name}={val}","messagePattern":"jax\\.numpy\\.arange: arguments must be scalars; got (.+?)=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":5956,"sourceCode":"\ndef _arange(start: ArrayLike | DimSize, stop: ArrayLike | DimSize | None = None,\n            step: ArrayLike | None = None, dtype: DTypeLike | None = None,\n            out_sharding: NamedSharding | None = None) -> Array:\n  # Validate inputs\n  if dtype is not None:\n    dtype = dtypes.check_and_canonicalize_user_dtype(dtype, \"arange\")\n  util.check_arraylike_or_none(\"arange\", start, stop, step)\n\n  # Ensure start/stop/step are concrete\n  start_name = \"stop\" if stop is None and step is None else \"start\"\n  start = core.concrete_or_error(None, start, f\"It arose in the jnp.arange argument '{start_name}'\")\n  stop = core.concrete_or_error(None, stop, \"It arose in the jnp.arange argument 'stop'\")\n  step = core.concrete_or_error(None, step, \"It arose in the jnp.arange argument 'step'\")\n\n  # Ensure start/stop/step are scalars\n  for name, val in [(start_name, start), (\"stop\", stop), (\"step\", step)]:\n    if val is not None and np.ndim(val) != 0:\n      raise ValueError(f\"jax.numpy.arange: arguments must be scalars; got {name}={val}\")\n\n  # Handle symbolic dimensions\n  if any(core.is_symbolic_dim(v) for v in (start, stop, step)):\n    if stop is None:\n      start, stop = 0, start\n    if step is None:\n      step = 1\n    return _arange_dynamic(start, stop, step, dtype or dtypes.default_int_dtype())\n\n  if dtype is None:\n    dtype = dtypes.result_type(start, *(x for x in [stop, step] if x is not None))\n  dtype = dtypes.jax_dtype(dtype)\n\n  if iscomplexobj(start) or iscomplexobj(stop) or iscomplexobj(step):\n    raise ValueError(\n        \"Passing complex start/stop/step to jnp.arange is no longer supported\"\n        \" starting in JAX v0.10.0.\")\n","sourceCodeStart":5938,"sourceCodeEnd":5974,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L5938-L5974","documentation":"Unlike NumPy, jnp.arange requires start, stop, and step to be scalar values (ndim == 0) because it must compute the output length statically for shape purposes. Passing any array with ndim > 0 raises this ValueError naming the offending argument and value.","triggerScenarios":"jnp.arange(jnp.array([0, 10])), jnp.arange(start=arr, stop=arr+5), or passing a shape tuple, e.g. jnp.arange(x.shape). Under jit, non-concrete values instead fail earlier in core.concrete_or_error.","commonSituations":"Using jnp.arange(x.shape[0]) works (scalar), but jnp.arange(x.shape) with a multi-dim shape fails; passing batched/traced bounds inside jitted code; iterating with array-valued endpoints.","solutions":["Extract a scalar dimension: jnp.arange(x.shape[0])","Use int(...) conversion for Python/numpy scalars: jnp.arange(int(stop))","For per-batch ranges, use vmap over a scalarized version or jnp.repeat-based construction"],"exampleFix":"// before\nidx = jnp.arange(x.shape)        # tuple/array of dims\n// after\nidx = jnp.arange(x.shape[0])     # scalar bound","handlingStrategy":"validation","validationCode":"for name, v in [('start', start), ('stop', stop), ('step', step)]:\n    if v is not None and np.ndim(v) != 0:\n        raise ValueError(f'{name} must be scalar')","typeGuard":"def is_scalar(v) -> bool:\n    return np.ndim(v) == 0","tryCatchPattern":null,"preventionTips":["Use x.shape[0] not x.shape for arange bounds","Convert traced bounds to Python ints via int() before arange when static"],"tags":["jax","arange","scalar-requirement","valueerror"],"backgroundTag":"non-scalar-argument-rejected","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}