Represent a Toeplitz matrix in an array

443 Views Asked by At

I need to represent a $n \times n$ Toeplitz matrix in a $2n - 1$ array. I need to create a function that takes a pair $(i,j)$ and returns the value in the $2n - 1$ array.

I am having a difficult time trying to calculate the index. Can you please help me?

1

There are 1 best solutions below

0
On BEST ANSWER

Store the top row first, then the left column without the first element. (e.g. {a,b,c,d,e,f,g,h,i) from the example in wiki)

Assuming (i, j) start at (0, 0) and end at (n-1, n-1),

if j >= i:
return array[j-i]
else:
return array[i-j+n]