xtensor-stack / xtensor

C++ tensors with broadcasting and lazy computing
BSD 3-Clause "New" or "Revised" License
3.36k stars 398 forks source link

Can't find functions finding the maximum and minimum values and indices of the entire matrix #2757

Closed AurusHuang closed 9 months ago

AurusHuang commented 10 months ago

I need an elegant method to find the maximum and minimum values and indices of the entire matrix, like the following:

xtensor<double, 3> mat_max;
// omitted: assigning values
double max_val=xt::Max(mat_max);
xarray<double, 3> max_idx=xt::Max_idx(mat_max);

Currently, there is argmax, but it gives flattened index instead of "unravelled" indices. Seems a foolish question but I really get nothing as much as I can find.

1013 seems providing an answer but not exactly what I want.

tdegeus commented 10 months ago

You should just use the unravel_index function as indicated, but I guess that you are right that this is different in NumPy.

github-actions[bot] commented 9 months ago

This issue is stale because it has been open for 30 days with no activity. It will be automatically closed in 14 days.

github-actions[bot] commented 9 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.