-
Notifications
You must be signed in to change notification settings - Fork 99
Open
Labels
bugThe problem described is something that must be fixedThe problem described is something that must be fixed
Description
Version of Awkward Array
2.8.10
Description and code to reproduce
Calling ak.moment with a weight array produces inflated results starting at n=2. The documentation states the formula. For weighted data this should evaluate to Σ weight * x**n / Σ weight, matching the usual definition of raw moments and aligning with the implementation of ak.var. However, the current implementation computes (x * weight) ** n before the reduction, effectively raising each weight to the nth power. This produces incorrect results whenever weights differ from 1.
import awkward as ak
data = ak.Array([1.0, 2.0])
weight = ak.Array([2.0, 3.0])
# Expected second raw moment: (2*1.0**2 + 3*2.0**2) / (2 + 3) = 14 / 5 = 2.8
expected = (2 * 1.0**2 + 3 * 2.0**2) / (2 + 3)
observed = ak.moment(data, 2, weight=weight, axis=None)
print("expected", expected)
print("observed", observed)expected 2.8
observed 8.0
Metadata
Metadata
Assignees
Labels
bugThe problem described is something that must be fixedThe problem described is something that must be fixed