keras-team/keras · error · ValueError
Expected a to have rank 2. Received: a.shape={a.shape}
Error message
Expected a to have rank 2. Received: a.shape={a.shape} What it means
Error "Expected a to have rank 2. Received: a.shape={a.shape}" thrown in keras-team/keras.
Source
Thrown at keras/src/ops/linalg.py:628
def _svd(x, full_matrices=True, compute_uv=True):
x = backend.convert_to_tensor(x)
_assert_2d(x)
return backend.linalg.svd(x, full_matrices, compute_uv)
class Lstsq(Operation):
def __init__(self, rcond=None, *, name=None):
super().__init__(name=name)
self.rcond = rcond
def call(self, a, b):
return backend.linalg.lstsq(a, b, rcond=self.rcond)
def compute_output_spec(self, a, b):
if len(a.shape) != 2:
raise ValueError(
f"Expected a to have rank 2. Received: a.shape={a.shape}"
)
if len(b.shape) not in (1, 2):
raise ValueError(
f"Expected b to have rank 1 or 2. Received: b.shape={b.shape}"
)
m, n = a.shape
if b.shape[0] != m:
raise ValueError(
"Expected b.shape[0] to be equal to "
"a.shape[0]. Received: "
f"a.shape={a.shape}, b.shape={b.shape}"
)
if len(b.shape) == 2:
k = b.shape[1]
x = KerasTensor((n, k), dtype=a.dtype)
else:
x = KerasTensor((n,), dtype=a.dtype)View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/ops/linalg.py:628 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/c4fd8b292616bb36.
Report an issue: GitHub.