当前位置: 首页 > wzjs >正文

西安专业建设网站城市建设服务中心网站

西安专业建设网站,城市建设服务中心网站,招聘外包服务公司,河南百度建个网站C中读取与保存不同维度的csv数据 一、保存csv数据1.1 一维vector1.2 二维vector1.3 三维vector1.4 五维vector 二、读取csv数据2.1 一维vector2.2 二维vector2.3 三维vector2.4 五维vector 一、保存csv数据 1.1 一维vector #include <iostream> #include <fstream&g…

C++中读取与保存不同维度的csv数据

  • 一、保存csv数据
    • 1.1 一维vector
    • 1.2 二维vector
    • 1.3 三维vector
    • 1.4 五维vector
  • 二、读取csv数据
    • 2.1 一维vector
    • 2.2 二维vector
    • 2.3 三维vector
    • 2.4 五维vector

一、保存csv数据

1.1 一维vector

#include <iostream>
#include <fstream>
#include <direct.h>
#include <io.h>
using namespace std;void Save_bias(vector<double> &bias, string names)
{string folderPath = "..//parameter_bias//" + names;if (0 != _access(folderPath.c_str(), 0)){_mkdir(folderPath.c_str());}ofstream pxData;pxData.open(folderPath + "//0.csv", std::ios::out | std::ios::trunc);for (int i = 0; i < bias.size(); i++){if (i == bias.size() - 1){pxData << bias[i] << std::endl;}else{pxData << bias[i] << ",";}}pxData.close();
}

1.2 二维vector

#include <iostream>
#include <fstream>
#include <direct.h>
#include <io.h>
using namespace std;void Save_means(vector<vector<double>> &means, string names)
{string folderPath = "..//parameter_mpvs//" + names;if (0 != _access(folderPath.c_str(), 0)){_mkdir(folderPath.c_str());}ofstream pxData;pxData.open(folderPath + "//0.csv", std::ios::out | std::ios::trunc);for (int i = 0; i < means.size(); i++){for (int j = 0; j < means[i].size(); j++){if (j == means[i].size() - 1){pxData << means[i][j] << std::endl;}else{pxData << means[i][j] << ",";}}}pxData.close();
}

1.3 三维vector

#include <iostream>
#include <fstream>
#include <direct.h>
#include <io.h>
using namespace std;void Save_weight(vector<vector<vector<double>>> &weight, string names)
{string folderPath = "..//parameter_weight//" + names;if (0 != _access(folderPath.c_str(), 0)){_mkdir(folderPath.c_str());}for (int j = 0; j < weight.size(); j++){ofstream pxData;if (j < 10){pxData.open(folderPath + "//0" + to_string(j) + ".csv", std::ios::out | std::ios::trunc);}else{pxData.open(folderPath + "//" + to_string(j) + ".csv", std::ios::out | std::ios::trunc);}for (int p = 0; p < weight[j].size(); p++){for (int q = 0; q < weight[j][p].size(); q++){if (q == weight[j][p].size() - 1){pxData << weight[j][p][q] << std::endl;}else{pxData << weight[j][p][q] << ",";}}}pxData.close();}
}

1.4 五维vector

#include <iostream>
#include <fstream>
#include <direct.h>
#include <io.h>
using namespace std;void Save_weight(vector<vector<vector<vector<vector<double>>>>> weight, string names)
{string init_file = "..//parameter_weight";if (0 != _access(init_file.c_str(), 0)){_mkdir(init_file.c_str());}string folderPath = init_file + "//" + names;if (0 != _access(folderPath.c_str(), 0)){_mkdir(folderPath.c_str());}for (int i = 0; i < weight.size(); i++){string folderPaths = folderPath + "//" + to_string(i);if (0 != _access(folderPaths.c_str(), 0)){_mkdir(folderPaths.c_str());}for (int j = 0; j < weight[i].size()*weight[i][0].size(); j++){ofstream pxData;if (j < 10 && weight[i].size()*weight[i][0].size() > 9){pxData.open(folderPaths + "//0" + to_string(j) + ".csv", std::ios::out | std::ios::trunc);}else{pxData.open(folderPaths + "//" + to_string(j) + ".csv", std::ios::out | std::ios::trunc);}for (int p = 0; p < weight[i][j / weight[i].size()][j % weight[i][0].size()].size(); p++){for (int q = 0; q < weight[i][j / weight[i].size()][j % weight[i][0].size()][p].size(); q++){if (q == weight[i][j / weight[i].size()][j % weight[i][0].size()][p].size() - 1){pxData << weight[i][j / weight[i].size()][j % weight[i][0].size()][p][q] << std::endl;}else{pxData << weight[i][j / weight[i].size()][j % weight[i][0].size()][p][q] << ",";}}}pxData.close();}}
}

二、读取csv数据

2.1 一维vector

#include <iostream>
#include <fstream>
using namespace std;void Read_bias(vector<double> &bias, string names)
{string folderPath = "..//parameter_bias//" + names;ifstream infile(folderPath + "//0.csv", ifstream::_Nocreate);string line, number;while (std::getline(infile, line)){istringstream is(line);vector<double> lineArray;while (std::getline(is, number, ',')){lineArray.push_back(atof(number.c_str()));}bias = lineArray;}
}

2.2 二维vector

#include <iostream>
#include <fstream>
using namespace std;void Read_means(vector<vector<double>> &means, string names)
{string folderPath = "..//parameter_means//" + names;ifstream infile(folderPath + "//0.csv", ifstream::_Nocreate);string line, number;while (std::getline(infile, line)){istringstream is(line);vector<double> lineArray;while (std::getline(is, number, ',')){lineArray.push_back(atof(number.c_str()));}means.push_back(lineArray);}
}

2.3 三维vector

#include <iostream>
#include <fstream>
using namespace std;void Read_weight(vector<vector<vector<double>>> &weight, string names)
{string folderPath = "..//parameter_weight//" + names;string dir;for (int j = 0; j < weight.size(); j++){ofstream pxData;if (j < 10){dir = folderPath + "//0" + to_string(j) + ".csv";}else{dir = folderPath + "//" + to_string(j) + ".csv";}ifstream infile(dir, ifstream::_Nocreate);string line, number;vector<vector<double>> x;while (std::getline(infile, line)){istringstream is(line);vector<double> lineArray;while (std::getline(is, number, ',')){lineArray.push_back(atof(number.c_str()));}x.push_back(lineArray);}weight[j] = x;}
}

2.4 五维vector

#include <iostream>
#include <fstream>
using namespace std;void Read_weight(vector<vector<vector<vector<vector<double>>>>> &_weight, string names)
{string dir_path = "..//parameter_weight";for (int i = 0; i < _weight.size(); i++){for (int j = 0; j < _weight[i].size()*_weight[i][0].size(); j++){string dir;if (j < 10 && _weight[i].size()*_weight[i][0].size() > 9){dir = dir_path + "//" + names + "//" + to_string(i) + "//0" + to_string(j) + ".csv";}else{dir = dir_path + "//" + names + "//" + to_string(i) + "//" + to_string(j) + ".csv";}ifstream infile(dir, ifstream::_Nocreate);string line, number;vector<vector<double>> x;while (std::getline(infile, line)){istringstream is(line);vector<double> lineArray;while (std::getline(is, number, ',')){lineArray.push_back(atof(number.c_str()));}x.push_back(lineArray);}_weight[i][j / _weight[i].size()][j % _weight[i][0].size()] = x;}}
}

文章转载自:

http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://00000000.ynbyk.cn
http://www.dtcms.com/wzjs/617729.html

相关文章:

  • 牛魔王网站建设苏州网站建设用哪种好
  • 网站开发项目合同餐饮管理培训课程
  • 东莞网站设计案例股票发行ipo和seo是什么意思
  • 网页制作与网站建设技术详解网站开发设计工程师
  • 网站开发需要人员安装网站模版视频
  • 如何用dw做网站前端网页小游戏免费的小游戏
  • 邢台学校网站建设费用国内十大网站制作公司
  • 南昌网站排名优化软件临沂网站制作定制
  • 网站建设整个流程wordpress 只有内页能打开
  • 南宁市营商环境建设局网站山西省两学一做网站
  • 手机网站推广服务如何加入小说网站做打字员
  • 福建建设人才与科技发展中心网站1个亿用户的服务器多少钱
  • 服务器里怎么建设网站网站建设的网站分析怎么写
  • 网盘做网站服务器小网站备案
  • 用wordpress建网站建设银行企业网上银行
  • 深圳三大巨头企业佛山网站的优化
  • 北京网站建设哪个好重庆网站公司制作价格
  • 简洁大方网站建设游戏类网站怎么做
  • 科技未来网站建设中国肩章大全
  • 棋牌代理平台合肥网站优化平台
  • 汕头站扩建进展品牌建设的意义和重要性
  • 英文网站定制公司什么叫网站降权
  • 湖北省级建设主管部门网站网站建设不好
  • 免费网站排名优化南宁市建设工程造价信息网
  • php网站的优势广元建设机械网站
  • 网站 建设 毕业设计 要求中国电信全渠道运营中心
  • 华侨城网站开发wordpress采集网站
  • 网站竞价 英文网站后台如何上传图片
  • 北京燕华工程建设有限公司网站工程网站建设方案
  • 电子商务网站建设特色0基础如何快速做网站