GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Performance of xt::nanmean · Issue #201 · xtensor-stack/xtensor-python Open DescriptionIn Python I have a 3D numpy array which is a stack of image data and I would like to calculate template<typename T> inline xt::pytensor<T, 2> nanmeanImages(const xt::pytensor<T, 3>& arr) { auto shape = arr.shape(); auto mean = xt::pytensor<T, 2>({shape[1], shape[2]}); for (std::size_t j=0; j < shape[1]; ++j) { for (std::size_t k=0; k < shape[2]; ++k) { T count = 0; T sum = 0; for (std::size_t i=0; i < shape[0]; ++i) { auto v = arr(i, j, k); if (! std::isnan(v)) { count += T(1); sum += v; } } mean(j, k) = sum / count; } } return mean; } template<typename T> inline xt::pytensor<T, 2> nanmeanImagesOld(const xt::pytensor<T, 3>& arr) { return xt::nanmean<T>(arr, {0}, xt::evaluation_strategy::immediate); } and benchmarked with the following Python code: The result is I guess the first one is faster because I would like to further improve the performance by using Activity
MetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |