Skip to content

Instantly share code, notes, and snippets.

@kevinhughes27
Last active July 22, 2023 00:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevinhughes27/6356673 to your computer and use it in GitHub Desktop.
Save kevinhughes27/6356673 to your computer and use it in GitHub Desktop.
Eigen3 Snips
using namespace Eigen;
// these are the typedefs I like to work with
typedef Matrix< double, Dynamic, 1, ColMajor > EVector;
typedef Matrix< double, Dynamic, Dynamic, ColMajor > EMatrix;
// Mean
EVector mean = X.rowwise().sum() / X.rows();
// Standard Deviation
EVector std = (X.rowwise() - mean.transpose()).array().pow(2).colwise().sum() / X.rows();
// Mean Center
EMatrix Xc = X.colwise() - mean;
@sohale
Copy link

sohale commented Jul 22, 2023

I think it's variance, not standard deviation, hence, it should be called var or a similar name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment