{"record":{"id":"c60baa828fbb3cc1","repo":"jax-ml/jax","slug":"need-at-least-one-array-to-concatenate","errorCode":null,"errorMessage":"Need at least one array to concatenate.","messagePattern":"Need at least one array to concatenate\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":4533,"sourceCode":"    reps_tup = tuple(iter(reps))  # pyrefly: ignore[no-matching-overload]\n  except TypeError:\n    reps_tup: tuple[DimSize, ...] = (reps,)\n  reps_tup = tuple(operator.index(rep) if core.is_constant_dim(rep) else rep\n                   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:","sourceCodeStart":4515,"sourceCodeEnd":4551,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L4515-L4551","documentation":"When concatenate receives a single ndarray (not a list) as fast path, _concatenate_array treats dimension 0 as the stack of inputs. A 0-d array or an empty leading dimension means there are zero arrays to concatenate, raising ValueError.","triggerScenarios":"jnp.concatenate(np.array([])) or jnp.concatenate(np.zeros((0, 3)), axis=1) — passing an ndarray whose first axis is empty instead of a list of arrays.","commonSituations":"A variable that is sometimes a list of arrays and sometimes a single array/empty array; np.asarray applied to a list before concatenate collapses it.","solutions":["Pass a sequence of arrays: jnp.concatenate(list_of_arrays, axis)","Guard empty inputs before calling concatenate"],"exampleFix":"// before\njnp.concatenate(np.asarray(chunks))\n// after\njnp.concatenate(chunks, axis=0)","handlingStrategy":"validation","validationCode":"assert not isinstance(arrays, np.ndarray) or arrays.ndim >= 2 and arrays.shape[0] > 0, 'no arrays to concatenate'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a list/tuple of arrays to concatenate, not an ndarray"],"tags":["jnp-concatenate","empty-sequence","value-error"],"backgroundTag":"empty-sequence-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}