{"record":{"id":"f63e99ac546d117b","repo":"jax-ml/jax","slug":"zero-dimensional-arrays-cannot-be-concatenated","errorCode":null,"errorMessage":"Zero-dimensional arrays cannot be concatenated.","messagePattern":"Zero-dimensional arrays cannot be concatenated\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":4537,"sourceCode":"                   for rep in reps_tup)\n  # lax.tile expects reps and A.shape to have the same rank.\n  reps_tup = (1,) * (A.ndim - len(reps_tup)) + reps_tup\n  if len(reps_tup) > np.ndim(A):\n    A = lax.expand_dims(\n        A, dimensions=tuple(range(len(reps_tup) - np.ndim(A))))\n  return lax.tile(A, reps_tup)\n\n\ndef _concatenate_array(arr: ArrayLike, axis: int | None,\n                       dtype: DTypeLike | None = None) -> Array:\n  # Fast path for concatenation when the input is an ndarray rather than a list.\n  arr = asarray(arr, dtype=dtype)\n  if arr.ndim == 0 or arr.shape[0] == 0:\n    raise ValueError(\"Need at least one array to concatenate.\")\n  if axis is None:\n    return lax.reshape(arr, (arr.size,))\n  if arr.ndim == 1:\n    raise ValueError(\"Zero-dimensional arrays cannot be concatenated.\")\n  axis = _canonicalize_axis(axis, arr.ndim - 1)\n  shape = arr.shape[1:axis + 1] + (arr.shape[0] * arr.shape[axis + 1],) + arr.shape[axis + 2:]\n  dimensions = [*range(1, axis + 1), 0, *range(axis + 1, arr.ndim)]\n  return lax.reshape(arr, shape, dimensions)\n\n\n@export\ndef concatenate(arrays: np.ndarray | Array | Sequence[ArrayLike],\n                axis: int | None = 0, dtype: DTypeLike | None = None) -> Array:\n  \"\"\"Join arrays along an existing axis.\n\n  JAX implementation of :func:`numpy.concatenate`.\n\n  Args:\n    arrays: a sequence of arrays to concatenate; each must have the same shape\n      except along the specified axis. If a single array is given it will be\n      treated equivalently to `arrays = unstack(arrays)`, but the implementation\n      will avoid explicit unstacking.","sourceCodeStart":4519,"sourceCodeEnd":4555,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L4519-L4555","documentation":"In the single-ndarray fast path of concatenate, a 1-D input array (after axis is not None) has no remaining dimensions to concatenate over — numpy semantics treat it as a list of scalars which jnp rejects for 1-D with a set axis.","triggerScenarios":"jnp.concatenate(np.array([1, 2, 3]), axis=0) — passing a 1-D ndarray directly instead of a list of arrays.","commonSituations":"Forgetting brackets: passing arr instead of [arr]; converting a list to ndarray before concatenate.","solutions":["Wrap the array in a list: jnp.concatenate([arr], axis)","Use axis=None if you wanted a flattened single-array result"],"exampleFix":"// before\njnp.concatenate(arr, axis=0)\n// after\njnp.concatenate([arr], axis=0)","handlingStrategy":"validation","validationCode":"assert np.ndim(arrays) >= 2 or isinstance(arrays, (list, tuple)), 'wrap single arrays in a list'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call jnp.concatenate([arr], axis) for a single array"],"tags":["jnp-concatenate","wrong-argument-form"],"backgroundTag":"wrong-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}