https://github.com/saliola/nonnegative_integer_matrices
code to generate and count nonnegative integer matrices with prescribe row and column sums (aka contingency tables)
https://github.com/saliola/nonnegative_integer_matrices
cython cython-examples numpy numpy-examples python3
Last synced: about 1 month ago
JSON representation
code to generate and count nonnegative integer matrices with prescribe row and column sums (aka contingency tables)
- Host: GitHub
- URL: https://github.com/saliola/nonnegative_integer_matrices
- Owner: saliola
- Created: 2025-03-02T03:21:33.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-06T02:36:32.000Z (about 1 year ago)
- Last Synced: 2025-09-01T01:24:53.123Z (9 months ago)
- Topics: cython, cython-examples, numpy, numpy-examples, python3
- Language: Jupyter Notebook
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Generating nonnegative integer matrices with prescribed row and column sums
Implementations in different languages of an algorithm to generate nonnegative
integer matrices with prescribed row and column sums. These are also known as
[contingency tables](https://en.wikipedia.org/wiki/Contingency_table).
## python
The file `nonneg_int_matrices.py` contains an example/test.
```bash
$ cd python
$ python nonneg_int_matrices.py
[[0, 3], [0, 1], [5, 0]]
[[0, 3], [1, 0], [4, 1]]
[[1, 2], [0, 1], [4, 1]]
[[1, 2], [1, 0], [3, 2]]
[[2, 1], [0, 1], [3, 2]]
[[2, 1], [1, 0], [2, 3]]
[[3, 0], [0, 1], [2, 3]]
[[3, 0], [1, 0], [1, 4]]
```
## numpy
Install numpy if it is not already installed:
```bash
$ pip install numpy
```
The file `nonneg_int_matrices.py` contains an example/test.
```bash
$ cd numpy
$ python nonneg_int_matrices.py
[[0 3]
[0 1]
[5 0]]
[[0 3]
[1 0]
[4 1]]
[[1 2]
[0 1]
[4 1]]
[[1 2]
[1 0]
[3 2]]
[[2 1]
[0 1]
[3 2]]
[[2 1]
[1 0]
[2 3]]
[[3 0]
[0 1]
[2 3]]
[[3 0]
[1 0]
[1 4]]
```
## cython
Install cython if it is not already installed:
```bash
$ pip install cython
```
The file `nonneg_int_matrices.py` contains an example/test.
```bash
$ cd cython
$ make
$ python nonneg_int_matrices.py
[[0, 3], [0, 1], [5, 0]]
[[0, 3], [1, 0], [4, 1]]
[[1, 2], [0, 1], [4, 1]]
[[1, 2], [1, 0], [3, 2]]
[[2, 1], [0, 1], [3, 2]]
[[2, 1], [1, 0], [2, 3]]
[[3, 0], [0, 1], [2, 3]]
[[3, 0], [1, 0], [1, 4]]
```
## cython with numpy
Install cython and numpy if not already installed:
```bash
$ pip install cython
$ pip install numpy
```
The file `nonneg_int_matrices.py` contains an example/test.
```bash
$ cd cython-with-numpy
$ make
$ python nonneg_int_matrices.py
[[0 3]
[0 1]
[5 0]]
[[0 3]
[1 0]
[4 1]]
[[1 2]
[0 1]
[4 1]]
[[1 2]
[1 0]
[3 2]]
[[2 1]
[0 1]
[3 2]]
[[2 1]
[1 0]
[2 3]]
[[3 0]
[0 1]
[2 3]]
[[3 0]
[1 0]
[1 4]]
```