{"record":{"id":"e053ce6c2ecfde6f","repo":"trekhleb/javascript-algorithms","slug":"matrix-is-not-of-2d-shape","errorCode":null,"errorMessage":"Matrix is not of 2D shape","messagePattern":"Matrix is not of 2D shape","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/algorithms/math/matrix/Matrix.js","lineNumber":50,"sourceCode":"const validate2D = (m) => {\n  validateType(m);\n  const aShape = shape(m);\n  if (aShape.length !== 2) {\n    throw new Error('Matrix is not of 2D shape');\n  }\n};","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/algorithms/math/matrix/Matrix.js#L32-L68","documentation":"Error \"Matrix is not of 2D shape\" thrown in trekhleb/javascript-algorithms.","triggerScenarios":"A 2D-only matrix operation (validate2D, e.g. via dot) receives a matrix whose computed shape length is not 2 — a flat 1D array or a 3D-or-higher nested array.","commonSituations":"Calling matrix multiplication or transpose with a vector or higher-dimensional matrix where a strictly 2D matrix is required.","solutions":["Pass a 2D matrix (array of row arrays) instead of a 1D vector or a 3D+ tensor.","Reshape or wrap the data as [[...], [...]] before calling dot or t.","Check shape(m).length === 2 before invoking operations restricted to 2D matrices."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"85293e3e2b88f4d2ce330d956b139cf628aa1e82","analyzedAt":"2026-08-24T05:59:10.417Z","schemaVersion":2},"datasetVersion":"2026-08-24T07:17:09.176Z"}