📄 rowstandard.cpp
字号:
#include <math.h>
/*使得矩阵每一行都为单位方差*/
void rowstandard (float *ans, int n, int p)
{
double tmp[2];
double tmp1;
int i, j;
for (i = 0; i < n; i++) {
tmp[0] = 0;
tmp[1] = 0;
for (j = 0; j < p; j++) {
tmp[0] += (double) ans[i * p + j];
tmp[1] += ((double) ans[i * p + j]) * ((double) ans[i * p + j]);
}
tmp[0] = tmp[0] / p;
tmp1 = (tmp[1] - p * (tmp[0]) * (tmp[0])) / (p - 1);
tmp[1] = sqrt (tmp1);
for (j = 0; j < p; j++) {
ans[i * p + j] =
(float) (((double) ans[i * p + j]) / tmp[1]);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -