You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, I really need to get around to putting a few brief examples into the readme. I only really use this class for storing multi-dimensional data, or for writing data to .npy files to then be used in Python after. For example, if you have N points each with an x, y, and z coordinate I would do something like:
#include<ndarray.hpp>
#include <vector>
struct Point {
double x, y, z;
}
const std::vector<Point>& get_points();
int main() {
const std::vector<Point>& points = get_points();
// The {points.size(), 3} is initialized to an
// std::vector<std::size_t> which is the shape of the array.
NDarray<double> points_out({points.size(), 3});
for (std::size_t i = 0; i < points.size(); i++) {
points_out(i, 0) = points[i].x;
points_out(i, 1) = points[i].y;
points_out(i, 2) = points[i].z;
}
// You can then save your data
points_out.save("points.npy");
return 0;
}
You could store the Point objects directly in the NDarray if you only need them in C++. The problem is the Point objects can't be written to the Numpy file directly, as this wouldn't be understood in Python.
I hope this helps ! I will try to added a few more examples to the readme in a few days.
Any simple example?
The text was updated successfully, but these errors were encountered: