My code is:
#include <istream>
#include <fstream>
#include <xtensor/xcsv.hpp>
int main()
{
std::ifstream in_file;
in_file.open("csv_file.csv");
auto data = xt::load_csv<std::string>(in_file);
return 0;
}
When I inspect the xt::xexpression
object data
in my IDE, it appears correctly dimensioned and populated, but I can't find a way to read its elements in the code.
After poring through the xtensor documentation I am no wiser... Perhaps a pointer to a good introduction to xtensor might answer this question.
After reading,
data
is simply anxarray
: a multi-dimensional array, or in the case of CSV typically a matrix. On the matrix you can operate much like for example in NumPy. For example:<<
allows you to print.operator()(...)
allows you to get an item using row and column indices.xt::view(data, ...)
allows you to get a 'slice'.To be more specific consider this example:
which for the following CSV file
prints: