I am writing smoothing spline in C++ using opencv.
I need to use sparse matrix (like in MATLAB), i.e. large matrix which consists of zeros and a few non-zero diagonals. I use Mat
matrices for this purpose, because I want to be able to multiply them, transpose them, etc.
Is there exist some elegant way to initialize such matrix, without processing it element after element?
There is a function called Mat::diag
, but this creates a column matrix, it is not what I need. Is it possible to convert this to normal
matrix? The most similar thing to what I need is Mat::eye
, but I need to initialize more than one diagonal, in addition, I have different numbers in same diagonal, so I cannot use Mat::eye
.
Thank you!