�
A��g�H � �� � d Z ddlmZ ddlZddlZddlmZmZ ddl m
Z
ddlmZ ddl
mZ dd lmZ dd
lmZ g d�Zd� Zd
� Z edg d�g � � Zddd�d�Zd� Zd� Zd� Zdd�ZdS )ax
Contingency table functions (:mod:`scipy.stats.contingency`)
============================================================
Functions for creating and analyzing contingency tables.
.. currentmodule:: scipy.stats.contingency
.. autosummary::
:toctree: generated/
chi2_contingency
relative_risk
odds_ratio
crosstab
association
expected_freq
margins
� )�reduceN� )�power_divergence�_untabulate)�
relative_risk)�crosstab)�
odds_ratio)�_make_tuple_bunch)�stats)�margins�
expected_freq�chi2_contingencyr �associationr r c �� �� g }t t | j � � � � }|D ]C�t j t j | �fd�|D � � � � }|� |� � �D|S )a 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
array([[ 0, 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10, 11]])
>>> m0, m1 = margins(a)
>>> m0
array([[15],
[51]])
>>> 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
array([[[ 60],
[ 92],
[124]]])
>>> m2
array([[[60, 66, 72, 78]]])
c � �� g | ]
}|�k �|��S � r )�.0�j�ks ��g/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/scipy/stats/contingency.py�
<listcomp>zmargins.<locals>.<listcomp>V s �� �-J�-J�-J�A�1��6�6�a�6�6�6� )�list�range�ndim�np�apply_over_axes�sum�append)�a�margsums�ranged�margr s @r r r '