jax-ml/jax · error · ValueError
Valid values for indexing are 'xy' and 'ij', got {indexing}
Error message
Valid values for indexing are 'xy' and 'ij', got {indexing} What it means
jnp.meshgrid's indexing argument must be exactly 'xy' (Cartesian, default) or 'ij' (matrix) indexing. Any other value raises this ValueError echoing the invalid value. The two modes differ in output shape ordering for two or more inputs.
Source
Thrown at jax/_src/numpy/lax_numpy.py:6094
[[10]
[20]
[30]]
2D matrix-index mesh grid:
>>> x_grid, y_grid = jnp.meshgrid(x, y, indexing='ij')
>>> print(x_grid)
[[1 1 1]
[2 2 2]]
>>> print(y_grid)
[[10 20 30]
[10 20 30]]
"""
args = list(util.ensure_arraylike_tuple("meshgrid", tuple(xi)))
if not copy:
raise ValueError("jax.numpy.meshgrid only supports copy=True")
if indexing not in ["xy", "ij"]:
raise ValueError(f"Valid values for indexing are 'xy' and 'ij', got {indexing}")
if any(a.ndim != 1 for a in args):
raise ValueError("Arguments to jax.numpy.meshgrid must be 1D, got shapes "
f"{[a.shape for a in args]}")
if indexing == "xy" and len(args) >= 2:
args[0], args[1] = args[1], args[0]
shape = [1 if sparse else a.shape[0] for a in args]
_a_shape = lambda i, a: [*shape[:i], a.shape[0], *shape[i + 1:]] if sparse else shape
output = [lax.broadcast_in_dim(a, _a_shape(i, a), (i,)) for i, a, in enumerate(args)]
if indexing == "xy" and len(args) >= 2:
output[0], output[1] = output[1], output[0]
return tuple(output)
@export
@api.jit
def i0(x: ArrayLike) -> Array:
r"""Calculate modified Bessel function of first kind, zeroth order.
View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use exactly 'xy' or 'ij' (lowercase)
- If outputs are transposed unexpectedly, switch between the two valid values rather than inventing new ones
Example fix
// before X, Y = jnp.meshgrid(x, y, indexing='yx') // after X, Y = jnp.meshgrid(x, y, indexing='ij')
Defensive patterns
Strategy: validation
Validate before calling
assert indexing in ('xy', 'ij') Type guard
from typing import Literal Indexing = Literal['xy', 'ij']
Prevention
- Type-annotate indexing as Literal['xy','ij']
- Centralize grid-construction helpers so the mode string is set once
When it happens
Trigger: jnp.meshgrid(x, y, indexing='XY') (wrong case), indexing='ji' (typo), or passing None. Note default is 'xy' in both NumPy and JAX.
Common situations: Confusion with other libraries (e.g. MATLAB conventions) or simple typos; users switching between 'xy' and 'ij' to fix downstream transposition bugs and mistyping the string.
Related errors
- Value of type {type(self)} is not convertible to integer ind
- TracerIntegerConversionError
- Unknown resize method "{s}"
- Use 'cuda', 'rocm', or 'oneapi' for lax.platform_dependent.
- 'trans' value must be 0, 1, or 2, got {trans}
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/884ab084501b7e5a.
Report an issue: GitHub.