This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / 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 : ndarray

The array for which to compute the marginal sums.

Returns

margsums : list of ndarrays

A list of length a.ndim. margsums[k] is the result of summing a over all axes except k; it has the same number of dimensions as a, but the length of each axis except axis k will 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