This is my code:
a <-c(1,2,3)
b <-t(a)
print(a*b)
I would expect the result to be 14, since a column vector multiplied with a row vector with fitting dimensions should be a skalar.
However, I get:
print (a*t(a))
[,1] [,2] [,3]
[1,] 1 4 9
Hence the partial sums instead of the whole sum. How can I fix this?
If what you essentially want is the sum of the products, then all you need is sum(a*a)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With