R语言 计算矩阵转置的交叉积 – tcrossprod()函数

R语言 计算矩阵转置的交叉积 – tcrossprod()函数

R语言中的 tcrossprod() 函数用于返回指定矩阵的转置的交叉积。

语法: tcrossprod(x)

参数:

x: 数字矩阵

例1 :

# R program to illustrate
# tcrossprod function
  
# Initializing a matrix with
# 2 rows and 2 columns
x <- matrix(1:4, 2, 2)
  
# Getting the matrix representation
x
  
# Calling the tcrossprod() function
tcrossprod(x)
R

输出

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

     [, 1] [, 2]
[1, ]   10   14
[2, ]   14   20
R

例2 :

# R program to illustrate
# tcrossprod function
  
# Initializing a matrix with
# 3 rows and 3 columns
x <- matrix(1:9, 3, 3)
  
# Getting the matrix representation
x
  
# Calling the tcrossprod() function
tcrossprod(x)
R

输出

     [, 1] [, 2] [, 3]
[1, ]    1    4    7
[2, ]    2    5    8
[3, ]    3    6    9

     [, 1] [, 2] [, 3]
[1, ]   66   78   90
[2, ]   78   93  108
[3, ]   90  108  126
R

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册