jax-ml/jax · error · ValueError
x must be a one-dimensional array
Error message
x must be a one-dimensional array
What it means
jnp.vander builds a power series design matrix from a single vector of sample points. It fires when x has ndim != 1, since per-column powers of a multidimensional input are not defined.
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
- After moving axes to end, leading shape of a must match…
- `alpha` must be one-dimensional; got alpha.shape=
- argmin and argmax require non-empty reduced dimension…
- Argument to Hessenberg reduction must have shape [..., n…
- Argument to symmetric eigendecomposition must have shape…
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/5d02329f25dad593.
Report an issue: GitHub.
Appendix: 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)