Eigen::VectorXf one_vector(3);
one_vector(0)=1;
one_vector(1)=2;
one_vector(2)=3;
float mean=one_vector.mean();
for (int i = 0; i < one_vector.rows(); i++)
{
one_vector(i)=one_vector(i)-mean;
}
float std=sqrt((one_vector.transpose()*one_vector)[0]/3);
std::cout<<"均值:"<<mean<<std::endl;
std::cout<<"标准差:"<<std<<std::endl;
输出:
均值:2
标准差:0.816497