Skip to contents

Given a list of matrices, returns a single matrix in which element (i, j) is the product of all corresponding elements (i, j) of all matrices in the list. Given a list of vectors, returns a single vector in which element i is the product of all corresponding elements i of all vectors in the list.

Usage

dotMatrix(matricesList)

Arguments

matricesList

a list of numeric matrices with same dimensions

Value

A matrix in which element (i,j) is the product of all corresponding elements (i,j) of all matrices in the original list

Examples

mat1 <- matrix(1:4, nrow = 2)
mat2 <- matrix(5:8, nrow = 2)
mat3 <- matrix(9:12, nrow = 2)
list_matrix <- list(mat1, mat2, mat3)
list_matrix
#> [[1]]
#>      [,1] [,2]
#> [1,]    1    3
#> [2,]    2    4
#> 
#> [[2]]
#>      [,1] [,2]
#> [1,]    5    7
#> [2,]    6    8
#> 
#> [[3]]
#>      [,1] [,2]
#> [1,]    9   11
#> [2,]   10   12
#> 

dotMatrix(list_matrix)
#>      [,1] [,2]
#> [1,]   45  231
#> [2,]  120  384