bundles / scipy latest / scipy / stats / contingency / margins
function
scipy.stats.contingency:margins
source: build-install/usr/lib/python3.14/site-packages/scipy/stats/contingency.py:41
Signature
def margins(a)Summary
Return a list of the marginal sums of the array a.
Parameters
a: ndarrayThe array for which to compute the marginal sums.
Returns
margsums: list of ndarraysA list of length
a.ndim.margsums[k]is the result of summingaover all axes exceptk; it has the same number of dimensions asa, but the length of each axis except axiskwill be 1.
Examples
import numpy as np from scipy.stats.contingency import margins✓
a = np.arange(12).reshape(2, 6) a m0, m1 = margins(a) m0 m1✓
array([[ 6, 8, 10, 12, 14, 16]])
b = np.arange(24).reshape(2,3,4) m0, m1, m2 = margins(b)✓
m0
✗array([[[ 66]],
[[210]]])
m1 m2✓
array([[[60, 66, 72, 78]]])
Aliases
scipy.stats.contingency.margins