Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-264

Tensor Matricization Unfold

Problem

Compute the mode-1 unfolding of a 2x2x2 tensor T, indexed as T[i][j][k].

The unfolding has one row per mode-1 index i, with the remaining indices flattened in row-major order: U[i][j * 2 + k] = T[i][j][k].

Hint

Matricization turns a tensor into a matrix so standard linear algebra can be applied to one mode.

Test cases

case 1
in: [[[[1,2],[3,4]],[[5,6],[7,8]]]]
expected: [[1,2,3,4],[5,6,7,8]]
case 2
in: [[[[1,0],[0,1]],[[2,0],[0,2]]]]
expected: [[1,0,0,1],[2,0,0,2]]
case 3
in: [[[[1,1],[1,1]],[[1,1],[1,1]]]]
expected: [[1,1,1,1],[1,1,1,1]]
case 4
in: [[[[0,1],[2,3]],[[4,5],[6,7]]]]
expected: [[0,1,2,3],[4,5,6,7]]
Starter codePython
def unfold_mode1(T):
    # Your code here
    pass

4 test cases · run your code against them in the editor