1

I'm doing a job with RcppArmadillo and trying to multiply a arma::cx_mat with a arma::mat, they are both size of 50x1000. but it raises a error: error: matrix multiplication: incompatible matrix dimensions: 50x1000 and 50x1000 ? why it happens? and what should I do ?

H.Ji
  • 175
  • 1
  • 2
  • 9
  • 1
    Been awhile since I've done matrix multiplication, but can't a 50x1000 matrix only be multiplied by a 1000x50 matrix? This is more of a math question than a programming one. – Carcigenicate Jul 14 '17 at 01:07
  • 3
    The inner dimension has to match, so a x b works with b x c, resulting in an a x c matrix. – Dirk Eddelbuettel Jul 14 '17 at 01:39
  • i was not clear in the question, what i want is the numerical multiplication, like c11 = a11*b11, c12=a12*b12, ... – H.Ji Jul 14 '17 at 02:58
  • 1
    If you want element-wise multiplication, use `%` instead of `*`. – Scarabee Jul 14 '17 at 08:18

1 Answers1

1

The inner dimensions need to be the same to take the matrix product. This would be true if you transposed the second matrix.

To multiply them element-wise (Hadamard product) with Rcpp, see Element-Wise Matrix Multiplication in Rcpp.

effel
  • 1,421
  • 1
  • 9
  • 17