Registered Member
|
how can one write the code below in more compact and faster way?
|
Moderator
|
int n = v.size();
vdiff = v.head(n-1) - v.tail(n-1); and for a matrix: int n = mat.rows(), m=mat.cols(); mdiff = mat.topLeftCorner(n-1,m-1) - mat.bottomRightCorner(n-1,m-1); |
Registered Member
|
Only small correction:
for vectors one should switch tail and head in order to get the result as described in the first post vdiff = v.tail(n-1) - v.head(n-1); |
Registered users: Baidu [Spider], Bing [Bot], Google [Bot], rblackwell