No project description provided
Project description
combin
Lightweight implementation of various combinatorics routines (Under construction!).
Current routines offered:
- Combinatorial number system ranking/unranking (
rank_to_comb
andcomb_to_rank
) - Binomial coefficient inversion (
inverse_choose
)
Installation
combin
is on PyPI and can be installed with the usual command:
python -m pip install combin
If this fails for your system, please file an issue.
Usage
combin
supports fast bijections to the combinatorial number system.
from combin import comb_to_rank, rank_to_comb
## 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) # from itertools
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
R = np.arange(comb(n,k))
C_lex = rank_to_comb(R, k=k, n=n, order='lex')
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
Built Distributions
File details
Details for the file combin-0.1.7.tar.gz
.
File metadata
- Download URL: combin-0.1.7.tar.gz
- Upload date:
- Size: 63.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d93774133750b697cd39c591443598c2d5f67e248fe4211403d12f422ae4e34 |
|
MD5 | cd6383a3c10e9f8fafcc27e3e67f46d3 |
|
BLAKE2b-256 | 043c01c6ba29e79165f94f4a4ca6c36be370e5b774ea2be3fe29432bedead71f |
File details
Details for the file combin-0.1.7-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: combin-0.1.7-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 119.8 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | efea6433c7eaf89063d0584fdef227036193adcb1bda2a8a212d43c92edeb89c |
|
MD5 | a3ea7ee973679efa5adba913c81d707b |
|
BLAKE2b-256 | 4bc6f17a07f2f181e605507b0fed2994e3c0c948a09dd020bf3cc7102e5fb9d9 |
File details
Details for the file combin-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: combin-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 157.9 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 218fa205505416fdff32a033ae01b6820000bd1c197ae4aef1676e073b8261bf |
|
MD5 | 71d56de76dc690eb9d7e646b3de7da5b |
|
BLAKE2b-256 | 9aa1b54b38df8ccfcb96426d2d684fe5bed54a5ed9e732e93da223d370a00b6e |
File details
Details for the file combin-0.1.7-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: combin-0.1.7-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 115.7 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ef9c6559b76c9ac004594ea7f0c3a92e3bfec637547a632ffd013547943dda3 |
|
MD5 | a5cfbca53c701a1e869921d0a72dc763 |
|
BLAKE2b-256 | e92a074cee3272b13463340ca105c12adbda71f40a4fb5ed2c915f74862b2dc4 |
File details
Details for the file combin-0.1.7-cp312-cp312-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: combin-0.1.7-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 121.7 kB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5258a5f4f75a719a625455eb899795174c886e8f240f8a02da3ece267d3a91c4 |
|
MD5 | 2ad9abbfdcc2de9692dea921a7e05f42 |
|
BLAKE2b-256 | 6542e10fd6144f372a5cfa24f21252f95ac8197bda1276e5d3441239d3e9d95c |
File details
Details for the file combin-0.1.7-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: combin-0.1.7-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 120.7 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31df8ba5b4ba9437deee80cd33b86b487e38d758388503c95b22fec708504c25 |
|
MD5 | aa8787a9e183df2f05a1122fe31bfc54 |
|
BLAKE2b-256 | 9b98b930d2b79de7b44459acaa3fb7b6c1cc8d8e57d8b056fbff180446a85c6f |
File details
Details for the file combin-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: combin-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 159.2 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d288682df7b68fc3dc26c44d8a3c364720a24c8715a354dd7f4e8499cdb69878 |
|
MD5 | c1be14090a7aaceda476f81b5187bf85 |
|
BLAKE2b-256 | d20f90b22540dfb5e7bf265e4ae03e9ab970e1f20f31fe69c1f68d4d81a43bc7 |
File details
Details for the file combin-0.1.7-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: combin-0.1.7-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 116.3 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfc181d483ee4cc3b0e90c0e4cf16cec0a3eaf5f457d0783b2ea393c22fc0263 |
|
MD5 | f89d98e3649bf052e810738a3947c4df |
|
BLAKE2b-256 | 20ff2d23bd9e62bbacb1e7b86eb52d55d4493546c131a01648190d64969ba38c |
File details
Details for the file combin-0.1.7-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: combin-0.1.7-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 122.3 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3e0142509068c7c1f8cd60fce35c31c5dcbed08cd89cf274352d2892c101058 |
|
MD5 | 51d29a8e9619f3d93cc0912cbca27f6c |
|
BLAKE2b-256 | ac612ad574c7e9c5d688bb4ff42f92577d0987f1b610ae35e83d68e2a9fe625b |
File details
Details for the file combin-0.1.7-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: combin-0.1.7-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 118.4 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f59405ba63975bb829dc11d3dd200cbf5dd4dcb38e1953d2619d1a5415f6632 |
|
MD5 | 67992b768d50c086d4609069b4c6a84a |
|
BLAKE2b-256 | 87d9759989f57347431ad3e760ce8889c9521275654872f72d4173e3596046f6 |
File details
Details for the file combin-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: combin-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 157.9 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5917120a57a5b7e27581753e9ee3012d742bf0b4bbf7825093c6cac44a566c7a |
|
MD5 | ed81c257e7fa1a34e558174376b42171 |
|
BLAKE2b-256 | 3708142717f7b789f450df8e427586ab0f5a9e736afd463df5cc8367967b9060 |
File details
Details for the file combin-0.1.7-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: combin-0.1.7-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 115.2 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ea1f37d312ae4d119c58c191d55b14daedd8cad6b6df39e3bed5dd2514ad39b |
|
MD5 | ca388342f2064794ad0b59bee18b2f56 |
|
BLAKE2b-256 | 864142ad6b171b9397086abf44746bc29af4340c66044b1b06dc601b2e62e5d4 |
File details
Details for the file combin-0.1.7-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: combin-0.1.7-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 120.8 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c796141355a1f480133cfed5a1566f2a20814f8b4bbf66deb41a129011087edd |
|
MD5 | 9b3518e03359d4108c32ecaddbea7231 |
|
BLAKE2b-256 | 91d3d0c69be882148415abb265d4d6210ca7f366771be3a68157de73cefee8c2 |
File details
Details for the file combin-0.1.7-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: combin-0.1.7-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 118.4 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52153101951bf337ac10d0eef4a89684b39d45b48191fc2fb158af75a88337f3 |
|
MD5 | 42ecdfc286277bed7d68fcc9d305187c |
|
BLAKE2b-256 | 12cbaf732aecf8bb62407fbf4386504a5417d59149a9124d442715a683e3481a |
File details
Details for the file combin-0.1.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: combin-0.1.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 159.7 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba5e675e00d8f8013f2d69e6bfc66b87fb8ac19b65a44eee3afc8bc10b604583 |
|
MD5 | ecdc26024c791bdf512bca35df4fe63a |
|
BLAKE2b-256 | e634d13a257032a7e0bee201e12c170c4d5e53fa005ba6c8c02969e7b7666e22 |
File details
Details for the file combin-0.1.7-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: combin-0.1.7-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 115.3 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a865cf3a3eb3b1c266bc73ab57f251ce5f09a71cd68b01facab09d65bc4e89f |
|
MD5 | 73d541cb8536f1e9b3bfd717143f20b8 |
|
BLAKE2b-256 | 8a2172d3b38f3a91f7210cb0cd7a1601b66fba8e821438c486a7693d03257249 |
File details
Details for the file combin-0.1.7-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: combin-0.1.7-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 120.8 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5aad089412e2042852d9bac787047a2d53c23d8224d53176406cb42ee51cf2f |
|
MD5 | 8236aa6b006845be4ddcda07435dd074 |
|
BLAKE2b-256 | d3372f9d247ae26b4b56f7f1263b8cddd69760b9429806147d31335aac1ba755 |
File details
Details for the file combin-0.1.7-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: combin-0.1.7-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 118.3 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 355dccfbf10bbd518b323f8a2444c2866aac643ce3734f458a1356e47ac1ca52 |
|
MD5 | e4efeddb3532e523bbef377cc5753d15 |
|
BLAKE2b-256 | 8574c4f163ee87adfef9d99a6d802c6e606dedef0c1d1141e985bbbb37ff1b72 |
File details
Details for the file combin-0.1.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: combin-0.1.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 158.9 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e5cde574cfd5348fe25d79b07c70a4dad4e0cb6a8381c9c7c00566e01ef978f |
|
MD5 | cc33d65c2364b8faf3193c6f39c53018 |
|
BLAKE2b-256 | 3e01292f0244c0d560f7342f2d8ab551af6017ffbd45f81aac737acad7a553f2 |
File details
Details for the file combin-0.1.7-cp38-cp38-macosx_11_0_arm64.whl
.
File metadata
- Download URL: combin-0.1.7-cp38-cp38-macosx_11_0_arm64.whl
- Upload date:
- Size: 115.2 kB
- Tags: CPython 3.8, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87588efbd5ec1cfd277ff44d83043dce4a905f1ffb180543f9475e8a78b978d4 |
|
MD5 | afa54a922d79a8cda6a15a856b9504bc |
|
BLAKE2b-256 | a839208259e68a67beef52f77ffd1fc9ddcf27bfcfaf33d4763a044ab19eaf1e |
File details
Details for the file combin-0.1.7-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: combin-0.1.7-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 120.8 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b71b5715ca33efb3bf1162361382ada5a6fd4af569f7b797f152688f556dfa2 |
|
MD5 | 555fda4a266e1017c8468a516b052c84 |
|
BLAKE2b-256 | 5cbb3b1eb9bbc349c5cd99ecf59a042af520c568b5c7dac5c78b76025d013986 |