Registry / data / ipfn
library1.4.4pypypi✓ verified 84d ago

ipfn is a Python library for iterative proportional fitting (IPF) with N dimensions. It is used to adjust contingency tables to match known marginal totals. The current version is 1.4.4. Release cadence is low; updates are infrequent.

pip install ipfn
INSTALL
IMPORT
SIG · IPFN
I
ipfn
datapythonv1.4.4
Install
7.5s avg
Import
936ms
Disk
164MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.940s · 164.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 7.5s · import 0.932s · 157MB
164MB installed
● package 164MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ipfn
from ipfn import ipfn
from ipfn import ipfn as ipf
Common alias is not standard; use as ipfn or alias explicitly

Basic example of iterative proportional fitting with two dimensions.

import numpy as np import pandas as pd from ipfn import ipfn # Seed marginal totals marginals = [np.array([100, 200]), np.array([150, 150])] # Original matrix Z = np.array([[50, 50], [150, 50]]) # Create IPF object and fit ipf = ipfn(Z, marginals, convergence_rate=1e-5, max_iteration=100) ipf.iterate() print(ipf.Z)
Debug
Known issues
gotchaThe `ipfn` function modifies the input array in-place. If you need to preserve the original matrix, pass a copy.
fix
Z_original = Z.copy() before calling ipfn.
affects: all
gotchaMarginal totals must be provided as a list of numpy arrays, not as a single array or pandas Series.
fix
Ensure marginals = [array1, array2] with matching dimensions.
affects: all
gotchaThe library does not validate that marginal sums match the total sum of the input matrix. Discrepancies may cause divergence.
fix
Check that sum of each marginal equals sum of Z before fitting.
affects: all
gotchaConvergence is not guaranteed; increase max_iteration or adjust convergence_rate if needed.
fix
Set max_iteration to a higher value (e.g., 1000) and convergence_rate to a looser tolerance (e.g., 1e-4).
affects: all
Errors
Common errors & fixes
TypeError: cannot unpack non-iterable int object
Passing a single integer as a marginal instead of an array.
fix
Wrap the integer in a numpy array: np.array([100])
ValueError: operands could not be broadcast together with shapes
Marginal dimensions do not match the original matrix dimensions.
fix
Check that each marginal array length matches the corresponding axis size of Z.
ImportError: cannot import name 'ipfn' from 'ipfn'
Old version of ipfn (before 1.0) used a different API.
fix
Upgrade to latest version: pip install --upgrade ipfn
Upgrade
Version history
1.4.4latest on PyPI · released Dec 30, 2021
Audit
Dependencies
numpyrequiredNumerical computations and array manipulations
pandasoptionalDataFrame support for input and output
Agent activity
6 hits · last 30 days
node
6
Resources
ipfn — pip install ipfn · libregistry