untensor.Rduntensor is more or less the inverse of to.tensor. It flattens tensorial dimensions. However the result is still a tensor.
untensor(X,i=NULL,name=NULL,pos=1,by=NULL)the tensor
the names of the dimensions to be removed and combined to a
single new
one as a character vector or a named list of character vectors if
the remove should be done in multiple chunks.
pos and name is in this case ignored.
the name of the new dimension to replace the others
where to insert the the new dimension
if i not given the dimensions to be kept
a tensor with the dimensions i removed.
The dimensions to be removed are gathered and
A <- to.tensor(1:64,c(a=2,b=2,c=2,d=2,e=2,f=2))
untensor(A,list(c(1,5),c(2,4)),name=c("i","j"))
#> , , 1, 1
#>
#> i
#> j [,1] [,2] [,3] [,4]
#> [1,] 1 2 17 18
#> [2,] 3 4 19 20
#> [3,] 9 10 25 26
#> [4,] 11 12 27 28
#>
#> , , 2, 1
#>
#> i
#> j [,1] [,2] [,3] [,4]
#> [1,] 5 6 21 22
#> [2,] 7 8 23 24
#> [3,] 13 14 29 30
#> [4,] 15 16 31 32
#>
#> , , 1, 2
#>
#> i
#> j [,1] [,2] [,3] [,4]
#> [1,] 33 34 49 50
#> [2,] 35 36 51 52
#> [3,] 41 42 57 58
#> [4,] 43 44 59 60
#>
#> , , 2, 2
#>
#> i
#> j [,1] [,2] [,3] [,4]
#> [1,] 37 38 53 54
#> [2,] 39 40 55 56
#> [3,] 45 46 61 62
#> [4,] 47 48 63 64
#>
#> attr(,"class")
#> [1] "tensor"
untensor(A,by=c("c","f"))
#> , , 1
#>
#> c
#> I1 [,1] [,2]
#> [1,] 1 5
#> [2,] 2 6
#> [3,] 3 7
#> [4,] 4 8
#> [5,] 9 13
#> [6,] 10 14
#> [7,] 11 15
#> [8,] 12 16
#> [9,] 17 21
#> [10,] 18 22
#> [11,] 19 23
#> [12,] 20 24
#> [13,] 25 29
#> [14,] 26 30
#> [15,] 27 31
#> [16,] 28 32
#>
#> , , 2
#>
#> c
#> I1 [,1] [,2]
#> [1,] 33 37
#> [2,] 34 38
#> [3,] 35 39
#> [4,] 36 40
#> [5,] 41 45
#> [6,] 42 46
#> [7,] 43 47
#> [8,] 44 48
#> [9,] 49 53
#> [10,] 50 54
#> [11,] 51 55
#> [12,] 52 56
#> [13,] 57 61
#> [14,] 58 62
#> [15,] 59 63
#> [16,] 60 64
#>
#> attr(,"class")
#> [1] "tensor"
untensor(A,c("a","d"))
#> , , 1, 1, 1
#>
#> b
#> I1 [,1] [,2]
#> [1,] 1 3
#> [2,] 2 4
#> [3,] 9 11
#> [4,] 10 12
#>
#> , , 2, 1, 1
#>
#> b
#> I1 [,1] [,2]
#> [1,] 5 7
#> [2,] 6 8
#> [3,] 13 15
#> [4,] 14 16
#>
#> , , 1, 2, 1
#>
#> b
#> I1 [,1] [,2]
#> [1,] 17 19
#> [2,] 18 20
#> [3,] 25 27
#> [4,] 26 28
#>
#> , , 2, 2, 1
#>
#> b
#> I1 [,1] [,2]
#> [1,] 21 23
#> [2,] 22 24
#> [3,] 29 31
#> [4,] 30 32
#>
#> , , 1, 1, 2
#>
#> b
#> I1 [,1] [,2]
#> [1,] 33 35
#> [2,] 34 36
#> [3,] 41 43
#> [4,] 42 44
#>
#> , , 2, 1, 2
#>
#> b
#> I1 [,1] [,2]
#> [1,] 37 39
#> [2,] 38 40
#> [3,] 45 47
#> [4,] 46 48
#>
#> , , 1, 2, 2
#>
#> b
#> I1 [,1] [,2]
#> [1,] 49 51
#> [2,] 50 52
#> [3,] 57 59
#> [4,] 58 60
#>
#> , , 2, 2, 2
#>
#> b
#> I1 [,1] [,2]
#> [1,] 53 55
#> [2,] 54 56
#> [3,] 61 63
#> [4,] 62 64
#>
#> attr(,"class")
#> [1] "tensor"