No project description provided
Project description
combin
Lightweight implementation of various routines known in combinatorics (Under construction!)
Current routines offered:
- Combinatorial number system ranking/unranking (
rank_to_comb
andcomb_to_rank
) - Binomial coefficient inversion (
inverse_choose
)
Usage
combin
supports fast bijections to the combinatorial number system.
from combin import comb_to_rank
## Fix k-combinations of an n-set
n = 10 # universe size
k = 3 # size of each combination
## Ranks each 3-tuple into its index in the combinatorial number system
C = combinations(range(n), k)
R = comb_to_rank(C, order='lex', n = n)
print(R)
# [0, 1, 2, ..., 119]
## If a generator is given, the default return type is a list
assert R == list(range(120))
# True
## Alternatively, combin has native support for NumPy arrays
C = np.fromiter(combinations(range(n), k), dtype=(np.int16, k))
assert np.all(comb_to_rank(C, order='lex', n=n) == np.arange(comb(n,k)))
# True
## An alternative bijection can also be chosen, such as the colexicographical order
## Note the colex order doesn't require the universe size (n)
print(comb_to_rank(C, order='colex'))
# [0, 1, 4, ..., 119]
## Unranking is just as easy: just supply n, k, and the order
from combin import rank_to_comb
R = np.arange(comb(n,k))
C_lex = rank_to_comb(R, k=k, n=n, order='lex')
assert np.all(C_lex == C)
print(f"Equal? {np.all(C_lex == C)}, combs: {C_lex}")
# Equal? True, combs: [[0, 1, 2], [0, 1, 3], [0, 1, 4], ..., [6, 8, 9], [7, 8, 9]]
## Uniformly sampling from k-combinations becomes trivial
ind = np.random.choice(range(comb(n,k)), size=10, replace=False)
random_combs = rank_to_comb(ind, k=k, order='colex')
# [[2, 7, 8], [1, 4, 6], ...]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
combin-0.1.4.tar.gz
(63.0 kB
view hashes)
Built Distributions
combin-0.1.4-cp39-cp39-win_amd64.whl
(116.0 kB
view hashes)
combin-0.1.4-cp38-cp38-win_amd64.whl
(115.8 kB
view hashes)
Close
Hashes for combin-0.1.4-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cc0fc41880f79ab2982e1cb98d7ccf3f230503d1ba8902b65e29cf68ee3d869 |
|
MD5 | 7eb35e81cef13d25d5a057c8478924a8 |
|
BLAKE2b-256 | afdd6556ebdf960451cc04270faeaa7b97e60c968b6d67706132d412ea2a5105 |
Close
Hashes for combin-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b0ab217d712ea6189905921fddc36a8a151408d0703fe08fb76572356f60596 |
|
MD5 | c34da32d6387d614d74474bd3ae5777e |
|
BLAKE2b-256 | a053b473b721198606ec07d8d766d12830eb413dea62d1bb029119858d27e2c0 |
Close
Hashes for combin-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12db8501c7e955c226eca8791fcbfcb84154a7e56c0bbc0e4ba0b972b1e8da49 |
|
MD5 | 513b62605c144044ca9eb5684cd176c2 |
|
BLAKE2b-256 | fb7700941b6a309cd8951951c01110bd1af7129dbe26e97d2b21615c96dd96e6 |
Close
Hashes for combin-0.1.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43ae04e9152986a1e147db047ebc66685e6411ba0457401c64d134410ba3a77a |
|
MD5 | 7e1c5a58aaa9652d5c4c624808108feb |
|
BLAKE2b-256 | 9d6b8605f98afd922293526c4d4bdc1573f2716a8ade019bc3975d76307df227 |
Close
Hashes for combin-0.1.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3268b79156a3ddf538e56d9b192739568f30f11ba5d1bbee081d2789f3f3a81 |
|
MD5 | d08a4689245f3aeacadcbdf079272aad |
|
BLAKE2b-256 | 1a6128fcd6d53f6ca354de57da467e3cec2e53e262c4a32cf0f242f4f611cf60 |
Close
Hashes for combin-0.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49dad2b657d9720554d28b78a67cba6fff75f8c01e120e7a01a10b2789eb9204 |
|
MD5 | 564036d9fb2dd75778ad3255b9178cac |
|
BLAKE2b-256 | 0ca110490e4c85b5721fb2c6f5c8281d39ddd9e41cea10b92f86e0ac475a234c |
Close
Hashes for combin-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da83979cbdd52f1bbb021f34b9fb06dba0ad18cffcab638256755a15abda91a6 |
|
MD5 | ebd8491daaa0034a806ff9e0e8e77abf |
|
BLAKE2b-256 | 42a5d82e774e893329668336c299dd57625713aff72dd286d813ba4699687dc4 |
Close
Hashes for combin-0.1.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93ff28c7dcf2b1209c585497f29a7039a9e83ad7746803d571d7bd23ec845020 |
|
MD5 | 81e43c1aeb59b782cd0259013b32967d |
|
BLAKE2b-256 | 56fbfc12e295e7a529758189841569e83ca21e2695ec80e9369de73c6bc694d8 |
Close
Hashes for combin-0.1.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 990addb0f03e3f55b9b9b6fc6367b2d1c754a9a6ba0d58e9f950f3028dae2e0f |
|
MD5 | 14ac0adb115f268168879e0c0b2bdfa8 |
|
BLAKE2b-256 | 61011adba14c151fe37b3b4ed303d3f3ca622498e1854a5ab0a748c5159fe357 |
Close
Hashes for combin-0.1.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 673ecfecb93bada49d1bd60e1e9eecda55092925b3e2d7413ab710adab21a21b |
|
MD5 | 429e69ed7325d47738968a5d8a016d69 |
|
BLAKE2b-256 | f0bfcd7c810313e3bc635b26916abd1bee860ba773b2ea8d6fea9e66c909b387 |
Close
Hashes for combin-0.1.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e67cfc89a8ce5fb2b29357777c6c83580a6e0ad967c25c80a0a02c5e73f739dc |
|
MD5 | c76cd9b8562021000aec93e025172adc |
|
BLAKE2b-256 | 5a21c1039cfe53b3d8792d0261715e34f4393a51bf74db4ba458d78bdba98ada |
Close
Hashes for combin-0.1.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 753322f39f8f7896c29f4594ac01fa79f8b16db0638fbece820f361a0e3e2a9e |
|
MD5 | 79f09280c42f57349e5aca4f59d4a408 |
|
BLAKE2b-256 | cafdf4697fa7f974d2458c45c30be146de04cc46a5fd13f10d1a74c4bf8d0c61 |
Close
Hashes for combin-0.1.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ddf1cc556b91a1ab7867b0d3dd940394267461a12757a607531152a9c0896a4 |
|
MD5 | 216b7f09f27b3831fa61b2a54e16459e |
|
BLAKE2b-256 | f7d3bdc75da10672dc4cf17c973e63d32cf23772be6736a2637a144f0d2cd2ca |
Close
Hashes for combin-0.1.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc014a46860651643a6c030190ece66a1a9f634b6ede8284c436a022a1b462e5 |
|
MD5 | c8da126cee3a0f2b3a3d521f680a3989 |
|
BLAKE2b-256 | 312557ffbc18a517bd4a5b70fb8054db80c9be7f2d39b561846612e7960f6740 |
Close
Hashes for combin-0.1.4-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8c4e39c5394aa7ada8c782c7de30eddafa673f9f43b855580a840f3e4b5187f |
|
MD5 | 6e7db2450f39efa91e142037b1206877 |
|
BLAKE2b-256 | 7a7b0d09b87aab4b7e9a273d43c154e8713e353422474d95228bb0594becea70 |
Close
Hashes for combin-0.1.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6a699ece614c6aa34f9496a58462714f0a733eee50f44d9ab1fc9c610487035 |
|
MD5 | c477ef1ca76d155c87eb05e359626995 |
|
BLAKE2b-256 | a2a264e0acd42792edab07b457dc358b95090d40448201d67b0de401f1b4209c |