{"record":{"id":"60f34fd5ad1d918a","repo":"keras-team/keras","slug":"both-input-arrays-must-be-arrays-of-2-or-3-dimen","errorCode":null,"errorMessage":"Both input arrays must be (arrays of) 2 or 3-dimensional vectors, but they are {x1_dim} and {x2_dim} dimensional instead.","messagePattern":"Both input arrays must be \\(arrays of\\) 2 or 3-dimensional vectors, but they are (.+?) and (.+?) dimensional instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/numpy/numpy.py","lineNumber":565,"sourceCode":"def cross(x1, x2, axisa=-1, axisb=-1, axisc=-1, axis=None):\n    axis = standardize_axis_for_numpy(axis)\n    x1 = convert_to_tensor(x1)\n    x2 = convert_to_tensor(x2)\n    dtype = dtypes.result_type(x1.dtype, x2.dtype)\n    x1 = x1.astype(dtype)\n    x2 = x2.astype(dtype)\n\n    if axis is not None:\n        axisa = axis\n        axisb = axis\n        axisc = axis\n    x1 = np.moveaxis(x1, axisa, -1)\n    x2 = np.moveaxis(x2, axisb, -1)\n\n    x1_dim = x1.shape[-1]\n    x2_dim = x2.shape[-1]\n    if x1_dim not in (2, 3) or x2_dim not in (2, 3):\n        raise ValueError(\n            \"Both input arrays must be (arrays of) 2 or 3-dimensional \"\n            f\"vectors, but they are {x1_dim} and {x2_dim} dimensional \"\n            \"instead.\"\n        )\n\n    # NumPy>=2.5 removed support for 2-dimensional vectors in `np.cross`\n    # (https://numpy.org/doc/stable/release/2.5.0-notes.html), so pad them\n    # to 3 dimensions ourselves (with an implicit zero z-component) before\n    # delegating the cross product of the resulting 3-dimensional vectors\n    # to `np.cross`.\n    def _pad_2d_vector_to_3d(x):\n        if x.shape[-1] == 2:\n            return np.pad(x, [(0, 0)] * (x.ndim - 1) + [(0, 1)])\n        return x\n\n    x1 = _pad_2d_vector_to_3d(x1)\n    x2 = _pad_2d_vector_to_3d(x2)\n","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/numpy/numpy.py#L547-L583","documentation":"The NumPy `cross` (vector cross product) implementation moves the vector axis to the end of each input and then checks that the resulting last dimension is 2 or 3 for both operands — cross products are only defined for 2D (with implied zero z) or 3D vectors. If either operand's vector dimension is any other size, this guard reports both dimensions (x1_dim and x2_dim) so you can see which input is not a stack of 2D/3D vectors.","triggerScenarios":"Thrown at keras/src/backend/numpy/numpy.py:565 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the axis picked by `axisa`/`axisb` (or `axis`) has size 2 or 3 on both inputs","Fix the axis arguments if the wrong dimension was treated as the vector axis","Pad 2D vectors to 3D or reshape inputs so the trailing vector dimension is 3"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}