Multiply each element in a vector by itself to create a matrix

后端 未结 1 1723
青春惊慌失措
青春惊慌失措 2020-12-06 19:44

I\'m trying to multiply each element in a vector by itself such that it produces a matrix that is symmetric about the diagonal. For example, given this vector::



        
相关标签:
1条回答
  • 2020-12-06 20:10

    Like this:

    x %o% x
    

    which is a shortcut for

    outer(x, x)
    

    You can also do

     tcrossprod(x)
    
    0 讨论(0)
提交回复
热议问题