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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.940s · 164.6MB
glibcpy 3.10–3.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)
Errors
Common errors & fixes
TypeError: cannot unpack non-iterable int object
Passing a single integer as a marginal instead of an array.
fixWrap 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.
fixCheck 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.
fixUpgrade 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