{ } Raw JSON

bundles / scipy latest / scipy / stats / contingency / margins

function

scipy.stats.contingency:margins

source: /scipy/stats/contingency.py :40

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.

Notes

Array API Standard Support

margins has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

====================  ====================  ====================
Library               CPU                   GPU
====================  ====================  ====================
NumPy                 ✅                     n/a                 
CuPy                  n/a                   ⛔                   
PyTorch               ⛔                     ⛔                   
JAX                   ⛔                     ⛔                   
Dask                  ⛔                     n/a                 
====================  ====================  ====================

See dev-arrayapi for more information.

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
b = np.arange(24).reshape(2,3,4)
m0, m1, m2 = margins(b)
m0
m1
m2

Aliases

  • scipy.stats.contingency.margins