Convert python numpy array to c ++ stl vector

I am looking for a way to read in C ++ a text file containing numpy arrays and put the data in vector< vector< ... > > , can anyone help me?

Many thanks. Archy

EDIT: text file format

 [[[ 0 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]]] 

Perhaps more readable:

 [ [ [ 0 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] ] ] 
+4
source share
2 answers
 float val; ::std::vector<float> vals; ifstream stream("c:/file.txt"); while(stream >> val) { vals.push_back(val); } 
0
source

It will depend on your level of knowledge.

If you are experienced, I would suggest something like Boost.Spirit.Qi , which is a real parser library. However, it may take some time to get used to.

Otherwise, it depends on what information you have at your disposal ... I will edit my answer when you provide us with more detailed information, since it is hairy enough to potentially complicate :)

0
source

Source: https://habr.com/ru/post/1306660/


All Articles