标签:float size 写入 time 空间 随机选择 return i++ ++
int split() {
float split = 0.2;
int split_row = split * row;
//20%用于预测,并为其开辟空间
testdata = (float **)malloc(split_row * sizeof(float *));
for (int k = 0; k < split_row; ++k) {
testdata[k] = (float *)malloc(col * sizeof(float));
}
//srand(1);
int t = 0;
while (t < split_row)//遍历所有的预测行
{
//int i = (int)((double)(row - t - 1)) * rand() / (double)(RAND_MAX); //随机选择第i行
srand(time(NULL)); /*初始化随zd机数种子*/
int i = rand() % (row-t-1); /*生成回一个[t,d)区间答内的整数*/
for (int j = 0; j < col; j++) {//遍历第i行,所有的列将其写入预测集
testdata[t][j] = data[i][j];
//printf("%f\n", testdata[t][j]);
}
for (int j = i; j <row ; j++)//将随机选中的第i行删除,即从第i行下面的所有行往上移,j+1行放在第j行
{
data[j] = data[j + 1];
}
t++;
}
/*
printf("testdata\n\n");
for (int i = 0; i < split_row; i++) {
for (int j = 0; j < col; j++)
printf("%f\t", testdata[i][j]);
printf("\n");
}
printf("data\n\n");
for (int i = 0; i < (row - split_row); i++) {
for (int j = 0; j < col; j++)
printf("%f\t", data[i][j]);
printf("\n");
}
*/
return split_row;
}
标签:float size 写入 time 空间 随机选择 return i++ ++
原文地址:https://www.cnblogs.com/lxwen/p/12814196.html