CS5106
error The matrix sizes do not fit (detail).
#What it means
A matrix operation got matrices whose sizes do not fit together. The detail in brackets gives the sizes. For example, multiplying needs the first matrix to have as many columns as the second has rows.
#Typical cause
- Multiplying two matrices with the same non-square shape.
- An operation that needs a square matrix (such as the inverse) given a rectangular one.
#How to fix it
Check the shapes with rows() and columns(), or transpose one matrix first (transpose()). See Collections.
#Example
//@chartscript 1
indicator("Matrix product")
const a = matrix.new<float>(2, 3, 1.0)
const b = matrix.new<float>(2, 3, 1.0)
const c = a.mult(b)
plot(c.rows())Fixed
//@chartscript 1
indicator("Matrix product")
const a = matrix.new<float>(2, 3, 1.0)
const b = matrix.new<float>(3, 2, 1.0)
const c = a.mult(b)
plot(c.rows())