1
$\begingroup$

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?

$\endgroup$
2
$\begingroup$

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]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.