All problems
Unvectorize Column-Major
Problem
Rebuild a rows x cols matrix from a flat vector stored in column-major order.
Column 0 occupies the first rows entries of vec, column 1 the next rows entries, and so on.
Hint
Entry (i, j) lives at index j * rows + i in the flat vector.
Test cases
case 1
in: [[1,3,2,4],2,2]
expected: [[1,2],[3,4]]
case 2
in: [[1,2,3],1,3]
expected: [[1,2,3]]
case 3
in: [[1,2,3],3,1]
expected: [[1],[2],[3]]
case 4
in: [[1,3,5,2,4,6],3,2]
expected: [[1,2],[3,4],[5,6]]
Starter codePython
def unvectorize_column_major(vec, rows, cols):
# Your code here
pass4 test cases · run your code against them in the editor