jax-ml/jax · error · ValueError
x must be a one-dimensional array
Error message
x must be a one-dimensional array
What it means
Raised by jnp.vander when the input x is not one-dimensional; the Vandermonde matrix is only defined for a 1-D vector of roots.
Source
Thrown at jax/_src/numpy/lax_numpy.py:8149
>>> jnp.vander(x, N=2)
Array([[1, 1],
[2, 1],
[3, 1],
[4, 1]], dtype=int32)
Generates the Vandermonde matrix in increasing order of powers, when
``increasing=True``.
>>> jnp.vander(x, increasing=True)
Array([[ 1, 1, 1, 1],
[ 1, 2, 4, 8],
[ 1, 3, 9, 27],
[ 1, 4, 16, 64]], dtype=int32)
"""
x = util.ensure_arraylike("vander", x)
if x.ndim != 1:
raise ValueError("x must be a one-dimensional array")
N = x.shape[0] if N is None else core.concrete_or_error(
operator.index, N, "'N' argument of jnp.vander()")
if N < 0:
raise ValueError("N must be nonnegative")
iota = lax.iota(x.dtype, N)
if not increasing:
iota = lax.sub(lax._const(iota, N - 1), iota)
return ufuncs.power(x[..., None], expand_dims(iota, tuple(range(x.ndim))))
### Misc
@export
def argwhere(
a: ArrayLike,
*,View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Flatten input: jnp.vander(x.ravel(), N)
- Use jax.vmap over rows if you need per-row Vandermonde matrices
- Fix upstream slicing to produce 1-D (x[:, 0] instead of x[:, :1])
Example fix
// before jnp.vander(x[:, :1]) # shape (n,1) // after jnp.vander(x[:, 0]) # shape (n,)
Defensive patterns
Strategy: validation
Validate before calling
x = jnp.asarray(x) if x.ndim != 1: x = x.ravel()
Type guard
def is_1d(x):
return jnp.asarray(x).ndim == 1 Prevention
- Ravel column slices (n,1) before vander
- Use vmap(jnp.vander) for batched Vandermonde
- Check .ndim of sliced inputs in data pipelines
When it happens
Trigger: jnp.vander on a 2-D matrix, a (n,1) column, or a list that asarray promotes to >1-D.
Common situations: Passing a column vector from slicing (shape (n,1)) instead of ravel; feeding a batch of points where per-row vander via vmap was intended.
Related errors
- scan got `length` argument of {} which disagrees with leadin
- conv_general_dilated batch_group_count must divide lhs batch
- conv_general_dilated rhs output feature dimension size must
- conv_general_dilated window and window_strides must have the
- Wrong number of explicit pads for convolution: expected {},
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/5d02329f25dad593.
Report an issue: GitHub.