{"record":{"id":"1dc5efefa471658c","repo":"jax-ml/jax","slug":"coordinates-must-be-a-sequence-of-length-input-ndi","errorCode":null,"errorMessage":"coordinates must be a sequence of length input.ndim, but {} != {}","messagePattern":"coordinates must be a sequence of length input\\.ndim, but (.+?) != (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/ndimage.py","lineNumber":80,"sourceCode":"\n\ndef _linear_indices_and_weights(coordinate: Array) -> list[tuple[Array, ArrayLike]]:\n  lower = jnp.floor(coordinate)\n  upper_weight = coordinate - lower\n  lower_weight = 1 - upper_weight\n  index = lower.astype(np.int32)\n  return [(index, lower_weight), (index + 1, upper_weight)]\n\n\n@api.jit(static_argnums=(2, 3, 4))\ndef _map_coordinates(input: ArrayLike, coordinates: Sequence[ArrayLike],\n                     order: int, mode: str, cval: ArrayLike) -> Array:\n  input_arr = jnp.asarray(input)\n  coordinate_arrs = [jnp.asarray(c) for c in coordinates]\n  cval = jnp.asarray(cval, input_arr.dtype)\n\n  if len(coordinates) != input_arr.ndim:\n    raise ValueError('coordinates must be a sequence of length input.ndim, but '\n                     '{} != {}'.format(len(coordinates), input_arr.ndim))\n\n  index_fixer = _INDEX_FIXERS.get(mode)\n  if index_fixer is None:\n    raise NotImplementedError(\n        'jax.scipy.ndimage.map_coordinates does not yet support mode {}. '\n        'Currently supported modes are {}.'.format(mode, set(_INDEX_FIXERS)))\n\n  if mode == 'constant':\n    is_valid = lambda index, size: (0 <= index) & (index < size)\n  else:\n    is_valid = lambda index, size: True\n\n  if order == 0:\n    interp_fun = _nearest_indices_and_weights\n  elif order == 1:\n    interp_fun = _linear_indices_and_weights\n  else:","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/ndimage.py#L62-L98","documentation":"jax.scipy.ndimage.map_coordinates requires one coordinate array per input axis; the number of coordinate arrays must equal input.ndim. Mismatch means JAX cannot align coordinates to axes.","triggerScenarios":"Passing [x] for a 2D image, or (row, col, batch) coordinates for a 2D input; passing a single array of shape (2, N) instead of a 2-sequence of (N,) arrays.","commonSituations":"Using np.stack([xs, ys]) as coordinates (one array) instead of (xs, ys); migrating from scipy where a single coordinates array of shape (ndim, N) is accepted.","solutions":["Pass a sequence/tuple of ndim arrays: coordinates=(rows, cols) for 2D","If you have a stacked (ndim, N) array, unpack it: coordinates=tuple(coords)","Verify input.ndim matches len(coordinates) before calling"],"exampleFix":"# before\ncoords = jnp.stack([ys, xs])  # shape (2, N)\nout = ndimage.map_coordinates(img, coords)\n# after\nout = ndimage.map_coordinates(img, (ys, xs))","handlingStrategy":"validation","validationCode":"coords = tuple(coords) if hasattr(coords, 'shape') and coords.ndim and coords.shape[0] == input.ndim else coords\nassert len(coords) == jnp.asarray(input).ndim","typeGuard":"def coords_match(coords, x) -> bool: return len(list(coords)) == jnp.asarray(x).ndim","tryCatchPattern":null,"preventionTips":["Always build coordinates as a tuple of per-axis arrays"],"tags":["jax","scipy","ndimage","coordinates","shape-mismatch"],"backgroundTag":"argument-shape-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}