Skip to content

Instantly share code, notes, and snippets.

@marty1885
Last active May 29, 2018 15:52
Show Gist options
  • Save marty1885/be5c822bb3f8883346be392d1fbe98cf to your computer and use it in GitHub Desktop.
Save marty1885/be5c822bb3f8883346be392d1fbe98cf to your computer and use it in GitHub Desktop.
decltype(auto) convertDataset(const xt::xarray<float>& X, const xt::xarray<float>& Y)
{
size_t numData = X.shape()[0];
std::vector<vec_t> x(numData);
std::vector<label_t> y(numData);
for(size_t i=0;i<numData;i++)
{
auto xb = xt::view(X, i, xt::all());
x[i] = vec_t(xb.begin(), xb.end());
auto yb = xt::view(Y, i, xt::all());
y[i] = xt::argmax(yb)[0];
}
//shuffle dataset
shuffle(x.begin(), x.end(), std::mt19937(42));
shuffle(y.begin(), y.end(), std::mt19937(42));
return std::tuple(x, y);
}
auto [x, y] = convertDataset(X, Y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment