ipfn
Iterative Proportional Fitting with N dimensions, for python
What it is and what it does
ipfn implements the iterative proportional fitting algorithm, a mathematical technique used in economics, demography, and social sciences to adjust a multidimensional contingency table so that its marginal sums (aggregates along one or more dimensions) match known target values. The package automatically selects between a fast numpy implementation and a slower but more user-friendly pandas implementation based on input type.
You provide an original array or dataframe, a list of target marginals, and the dimensions along which each marginal should apply. The algorithm iteratively rescales the table until convergence. It exposes control over iteration limits, convergence tolerance, and verbosity, returning either the fitted result, a success flag, or detailed iteration diagnostics depending on the verbosity level.
Use it for:
- Adjust population survey data to match known demographic totals across multiple geographic and age categories.
- Rescale economic input-output tables to match independently estimated row and column sums.
- Balance contingency tables in social science research when marginal distributions are known but cell values are uncertain.
- Calibrate multidimensional traffic or flow models to match observed aggregate counts on subsets of dimensions.
- Prepare synthetic microdata by adjusting initial samples to match target distributions on multiple cross-tabulated variables.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Iterative proportional fitting algorithm that adjusts multidimensional arrays or dataframes so their aggregates along specified dimensions match target marginals, with both fast numpy and slower pandas implementations.
Yes, if you need iterative proportional fitting and can tolerate dormancy. The package is stable and low-friction to install, with no known vulnerabilities and a permissive MIT license. However, expect no active maintenance—last release was 2021-12-30. Use it for well-understood IPF problems; do not expect bug fixes or updates if you encounter edge cases.
Install
ipfn on PyPI
pip
pip install ipfnuv
uv add ipfnpoetry
poetry add ipfnInstalling ipfn
Before you install
Low friction install with only pandas and numpy as runtime dependencies. Package is dormant—last release was 2021-12-30 and last commit 2024-05-10, so expect no active maintenance or bug fixes.
License in practice
MIT license is permissive, allowing commercial and private use with minimal restrictions; you may use and modify freely provided you retain the license notice.
Quickstart
import numpy as np
from ipfn import ipfn
m = np.array([[40, 30, 20, 10], [35, 50, 100, 75], [30, 80, 70, 120], [20, 30, 40, 50]])
xip = np.array([150, 300, 400, 150])
xpj = np.array([200, 300, 400, 100])
IPF = ipfn.ipfn(m, [xip, xpj], [[0], [1]], convergence_rate=1e-6)
m_fitted = IPF.iteration()
print(m_fitted)
Verify before relying
- Whether the algorithm converges reliably on all input types and dimensions, or if certain edge cases are known to fail.
- Performance characteristics on large multidimensional arrays relative to the R ipfp package it claims equivalence with.
- Whether dormancy means the package is stable-complete or abandoned and no longer maintained.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pandas, numpy |
| Maintenance | dormant — 1,688 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 102,246/month — #12,881 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: ipfn-1.4.4-py2.py3-none-any.whl
Keywords: iterative, proportional, fitting, ipfp, biproportional, ras, raking, scaling
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
awkward-pandasExtends pandas DataFrames to store and…
permissive · top 15,000 on PyPI
numpy-groupiesProvides optimized group-indexing operations on…
permissive · top 15,000 on PyPI
swifterSwifter applies functions to DataFrames and…
unclear · top 5,000 on PyPI
itablesRenders Pandas and Polars DataFrames as…
permissive · top 5,000 on PyPI
Pint-PandasPint-Pandas adds physical unit support to…
permissive · top 15,000 on PyPI
nptypingProvides type hints and runtime type checking…
permissive · top 15,000 on PyPI
sklearn-pandasBridges pandas DataFrames and scikit-learn by…
permissive · top 15,000 on PyPI
pandas-read-xmlConverts XML files into pandas DataFrames, with…
permissive · top 15,000 on PyPI
piecewise-rationalPerforms shape-preserving piecewise rational…
permissive · top 15,000 on PyPI
datacompyDataComPy compares two DataFrames across…
permissive · top 5,000 on PyPI