A tensor can be seen as a linear mapping of a tensor to a tensor. This function gives the corresponding matrix of the mapping.

to.matrix.tensor(X,i,j,by=NULL)

Arguments

X

The tensor

i

The image indices of the linear mapping

j

The domain indices of the linear mapping

by

the operation is done in parallel for these dimensions

Value

if no by is given a matrix. Otherwise a tensor of level 2+length(dim(X))[by] giving matrices for each specification of the by dimensions.

Details

A tensor can be seen as a linear mapping of a tensor to a tensor. This function computes the corresponding matrix, mapping the entries of the domain tensor to the entries of the image tensor.

Author

K. Gerald van den Boogaart

Examples

A <- reorder.tensor(to.tensor(1:30,c(a=2,b=3,c=5)),c("c","a","b"))

to.matrix.tensor(A,"a",c("b","c"))              # matrix(1:30,nrow=2)
#>       
#>        [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#>   [1,]    1    3    5    7    9   11   13   15   17    19    21    23    25
#>   [2,]    2    4    6    8   10   12   14   16   18    20    22    24    26
#>       
#>        [,14] [,15]
#>   [1,]    27    29
#>   [2,]    28    30

to.matrix.tensor(A,c("a","b"),c("c"))           # matrix(1:30,nrow=6)
#>       
#>        [,1] [,2] [,3] [,4] [,5]
#>   [1,]    1    7   13   19   25
#>   [2,]    2    8   14   20   26
#>   [3,]    3    9   15   21   27
#>   [4,]    4   10   16   22   28
#>   [5,]    5   11   17   23   29
#>   [6,]    6   12   18   24   30

to.matrix.tensor(A,c("a","b"),by=c("c")) # structure(1:30,dim=c(6,1,5)))
#> , , 1
#> 
#>       
#>        [,1]
#>   [1,]    1
#>   [2,]    2
#>   [3,]    3
#>   [4,]    4
#>   [5,]    5
#>   [6,]    6
#> 
#> , , 2
#> 
#>       
#>        [,1]
#>   [1,]    7
#>   [2,]    8
#>   [3,]    9
#>   [4,]   10
#>   [5,]   11
#>   [6,]   12
#> 
#> , , 3
#> 
#>       
#>        [,1]
#>   [1,]   13
#>   [2,]   14
#>   [3,]   15
#>   [4,]   16
#>   [5,]   17
#>   [6,]   18
#> 
#> , , 4
#> 
#>       
#>        [,1]
#>   [1,]   19
#>   [2,]   20
#>   [3,]   21
#>   [4,]   22
#>   [5,]   23
#>   [6,]   24
#> 
#> , , 5
#> 
#>       
#>        [,1]
#>   [1,]   25
#>   [2,]   26
#>   [3,]   27
#>   [4,]   28
#>   [5,]   29
#>   [6,]   30
#> 
to.matrix.tensor(A,c("a"),by=c("c"))     # structure(1:30,dim=c(2,3,5)))
#> , , 1
#> 
#>       
#>        [,1] [,2] [,3]
#>   [1,]    1    3    5
#>   [2,]    2    4    6
#> 
#> , , 2
#> 
#>       
#>        [,1] [,2] [,3]
#>   [1,]    7    9   11
#>   [2,]    8   10   12
#> 
#> , , 3
#> 
#>       
#>        [,1] [,2] [,3]
#>   [1,]   13   15   17
#>   [2,]   14   16   18
#> 
#> , , 4
#> 
#>       
#>        [,1] [,2] [,3]
#>   [1,]   19   21   23
#>   [2,]   20   22   24
#> 
#> , , 5
#> 
#>       
#>        [,1] [,2] [,3]
#>   [1,]   25   27   29
#>   [2,]   26   28   30
#>