I am trying to get a function that is the opposite of diff() I want to add the values of adjacent columns in a matrix for each column in the matrix. I do NOT need the sum of the entire column or row. For example:
如果我说:
[ 1 2 4;
3 5 8 ]
我最后会与:
[ 3 6;
8 13 ]
当然,只要一两栏,这很简单,因为我可以做 x[,1,1]+x[,2],但这些矩阵相当大。
我感到惊讶的是,我似乎无法找到有效办法这样做。