Multiply by two vectors – I want a scalar, but I get a vector?

This is my code:

a <-c(1,2,3)
b <-t(a)
print(a*b)

I expect the result to be 14, because the multiplication of the column vector and the row vector with fitting size should be SKALAR

However, I get:

[,1] [,2] [,3]

[1,]    1    4    9

Therefore, partial sums are not integers How to solve this problem?

Solution

If what you want is the sum of products, what you need is sum (a * a)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>