Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用旧矩阵值作为指数在R中创建新矩阵_R_Matrix - Fatal编程技术网

使用旧矩阵值作为指数在R中创建新矩阵

使用旧矩阵值作为指数在R中创建新矩阵,r,matrix,R,Matrix,如果我有矩阵mat1 [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 可以通过一个非常简单的命令将所有单个值平方为 mat1 * mat1 [,1] [,2] [,3] [1,] 1 9 25 [2,] 4 16 36 现在,我想做的是创建一个新的矩阵,其中所有值都由e^(旧值)计算,例如e^1,e^2,e^3等等。我怎样才能做到这一点呢?exp计算指数函数 > mat1

如果我有矩阵mat1

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
可以通过一个非常简单的命令将所有单个值平方为

mat1 * mat1

     [,1] [,2] [,3]
[1,]    1    9   25
[2,]    4   16   36

现在,我想做的是创建一个新的矩阵,其中所有值都由
e^(旧值
)计算,例如
e^1
e^2
e^3
等等。我怎样才能做到这一点呢?

exp
计算指数函数

> mat1 <- matrix(1:6, nrow=2)
> exp(mat1)
         [,1]     [,2]     [,3]
[1,] 2.718282 20.08554 148.4132
[2,] 7.389056 54.59815 403.4288
>mat1 exp(mat1)
[,1]     [,2]     [,3]
[1,] 2.718282 20.08554 148.4132
[2,] 7.389056 54.59815 403.4288

exp
计算指数函数

> mat1 <- matrix(1:6, nrow=2)
> exp(mat1)
         [,1]     [,2]     [,3]
[1,] 2.718282 20.08554 148.4132
[2,] 7.389056 54.59815 403.4288
>mat1 exp(mat1)
[,1]     [,2]     [,3]
[1,] 2.718282 20.08554 148.4132
[2,] 7.389056 54.59815 403.4288