Suppose \$$A\$$ is row vector, and \$$B\$$ is a column vector, and we wish to form their dot product \$$A \cdot B\$$.

Now clearly this will only work if the number of columns in \$$A\$$ equals the number of rows in \$$B\$$.

And _that_ is the general compatibility requirement for \$$A\$$ and \$$B\$$, in order for the product of \$$A\$$ and \$$B\$$ to be defined:

\$ncols(A) = nrows(B)\$