keras-team/keras · error · ValueError
Both input arrays must be (arrays of) 2 or 3-dimensional vec
Error message
Both input arrays must be (arrays of) 2 or 3-dimensional vectors, but they are {x1_dim} and {x2_dim} dimensional instead. What it means
Error "Both input arrays must be (arrays of) 2 or 3-dimensional vectors, but they are {x1_dim} and {x2_dim} dimensional instead." thrown in keras-team/keras.
Source
Thrown at keras/src/backend/numpy/numpy.py:565
def cross(x1, x2, axisa=-1, axisb=-1, axisc=-1, axis=None):
axis = standardize_axis_for_numpy(axis)
x1 = convert_to_tensor(x1)
x2 = convert_to_tensor(x2)
dtype = dtypes.result_type(x1.dtype, x2.dtype)
x1 = x1.astype(dtype)
x2 = x2.astype(dtype)
if axis is not None:
axisa = axis
axisb = axis
axisc = axis
x1 = np.moveaxis(x1, axisa, -1)
x2 = np.moveaxis(x2, axisb, -1)
x1_dim = x1.shape[-1]
x2_dim = x2.shape[-1]
if x1_dim not in (2, 3) or x2_dim not in (2, 3):
raise ValueError(
"Both input arrays must be (arrays of) 2 or 3-dimensional "
f"vectors, but they are {x1_dim} and {x2_dim} dimensional "
"instead."
)
# NumPy>=2.5 removed support for 2-dimensional vectors in `np.cross`
# (https://numpy.org/doc/stable/release/2.5.0-notes.html), so pad them
# to 3 dimensions ourselves (with an implicit zero z-component) before
# delegating the cross product of the resulting 3-dimensional vectors
# to `np.cross`.
def _pad_2d_vector_to_3d(x):
if x.shape[-1] == 2:
return np.pad(x, [(0, 0)] * (x.ndim - 1) + [(0, 1)])
return x
x1 = _pad_2d_vector_to_3d(x1)
x2 = _pad_2d_vector_to_3d(x2)
View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/backend/numpy/numpy.py:565 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/60f34fd5ad1d918a.
Report an issue: GitHub.