All problems
Circulant Matrix
Problem
Build the circulant matrix whose first row is the vector v.
Each subsequent row is the previous row shifted right by one, wrapping around: C[i][j] = v[(j - i) % n].
Hint
The matrix is uniquely determined by its first row because each diagonal is constant.
Test cases
case 1
in: [[1,2,3]]
expected: [[1,2,3],[3,1,2],[2,3,1]]
case 2
in: [[1,0]]
expected: [[1,0],[0,1]]
case 3
in: [[5]]
expected: [[5]]
case 4
in: [[1,2,3,4]]
expected: [[1,2,3,4],[4,1,2,3],[3,4,1,2],[2,3,4,1]]
Starter codePython
def circulant_matrix(v):
# Your code here
pass4 test cases · run your code against them in the editor