From 823e69ce16366d9aa0889f816a0e737f9f9c8e37 Mon Sep 17 00:00:00 2001 From: Iason Krommydas Date: Thu, 13 Nov 2025 03:41:53 -0600 Subject: [PATCH 1/2] fix moment calculation --- src/awkward/operations/ak_moment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/awkward/operations/ak_moment.py b/src/awkward/operations/ak_moment.py index 882da992e2..c17eb4c1fb 100644 --- a/src/awkward/operations/ak_moment.py +++ b/src/awkward/operations/ak_moment.py @@ -73,7 +73,7 @@ def moment( Passing all arguments to the reducers, the moment is calculated as - ak.sum((x*weight)**n) / ak.sum(weight) + ak.sum(weight * x**n) / ak.sum(weight) The `n=2` moment differs from #ak.var in that #ak.var also subtracts the mean (the `n=1` moment). @@ -148,7 +148,7 @@ def _impl( attrs=ctx.attrs, ) sumwxn = ak.operations.ak_sum._impl( - (x * weight) ** n, + (x**n) * weight, axis, keepdims, mask_identity, From 0195c4b4fa3dd180ab5466a6b696792c72424e49 Mon Sep 17 00:00:00 2001 From: Iason Krommydas Date: Thu, 13 Nov 2025 03:45:28 -0600 Subject: [PATCH 2/2] docstring --- src/awkward/operations/ak_moment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/awkward/operations/ak_moment.py b/src/awkward/operations/ak_moment.py index c17eb4c1fb..e8433a02b6 100644 --- a/src/awkward/operations/ak_moment.py +++ b/src/awkward/operations/ak_moment.py @@ -73,7 +73,7 @@ def moment( Passing all arguments to the reducers, the moment is calculated as - ak.sum(weight * x**n) / ak.sum(weight) + ak.sum(x**n * weight) / ak.sum(weight) The `n=2` moment differs from #ak.var in that #ak.var also subtracts the mean (the `n=1` moment).