-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRead_Data.cpp
50 lines (45 loc) · 1.08 KB
/
Read_Data.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "Read_Data.hpp"
std::vector<std::string> load_file(std::string filename)
{
std::ifstream f(filename, std::ios_base::in);
std::string temp;
std::vector<std::string> data;
while (std::getline(f, temp)) {
data.push_back(temp);
}
f.close();
return data;
}
void get_pixel_data(std::vector<std::string> data, std::vector<int> &result,
std::vector<std::vector<int>> &pixel_data)
{
// 1st line is useless
data.erase(data.begin());
result.clear();
pixel_data.clear();
// Now we split the lines at ',' position
for (std::string a : data) {
std::string temp = "";
std::vector<int> pixel;
for (char s : a) {
if (s == ',') {
pixel.push_back(stoi(temp));
temp = "";
}
else {
temp += s;
}
}
pixel.push_back(std::stoi(temp));
result.push_back(pixel[0]);
pixel.erase(pixel.begin());
pixel_data.push_back(pixel);
}
}
// int main()
// {
// load_file("Dataset/train.csv");
// get_pixel_data();
// std::cout << pixel_data[0].size() << "\n";
// std::cout << result.size() << "\n";
// }