How would you preprocess 2 dimensional data to have 0 mean? Say you have a matrix $M $ that is $p \times q $. Would you calculate the mean of each row, get a vector of length $q $ and subtract each element of the vector from the corresponding column?
2026-03-27 12:00:36.1774612836
On
Data preprocessing
92 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
0
On
Let $M$ be of size $p \times q$, as stated in your question. If you want the mean of the entire array to be zero:
M = M - mean(M(:));
If you want each column individually to have zero mean:
M = M - repmat(mean(M,1), p, 1);
If you want each row individually to have zero mean:
M = M - repmat(mean(M,2), 1, q);
If your data are 2-dimensional, then the matrix $M$ would have the size $p \times 2$ or $2 \times p$. In either case, you need to take the mean along the $p$ dimension. This will give you a 2-element mean vector $m$. Then you have to subtract it from every row (or column) of $M$.