Skip to main content

ndplex

The n-Dimensional m-Plex array: a generic Pascal's array for NumPy.

ndplex builds Pascal's rectangle, cube or hypercube as a NumPy array, and lets you change everything that defines it: the values on its edges, the rule that generates each interior node, and which neighbours that rule reads. It can then cut lines and cross-sections through the array, show the array as a triangle, tetrahedron or n-simplex, and look its rows up in the On-Line Encyclopedia of Integer Sequences.

Install

pip install ndplex

In Google Colab, run !pip install ndplex in a cell. ndplex needs Python 3.10 or later and NumPy 1.23.5 or later, nothing else. oeis needs a network connection when it is called.

Quick start

By default, ndplex(n) is Pascal's rectangle: ones on the top and left edges, and every other node the sum of the node above it and the node to its left.

>>> from ndplex import ndplex
>>> p = ndplex(6)
>>> print(p)
[[  1   1   1   1   1   1]
 [  1   2   3   4   5   6]
 [  1   3   6  10  15  21]
 [  1   4  10  20  35  56]
 [  1   5  15  35  70 126]
 [  1   6  21  56 126 252]]

as_tri shows the same array as Pascal's triangle, justified left, or returns the sum of each row.

>>> print(p.as_tri())
[[ 1  0  0  0  0  0]
 [ 1  1  0  0  0  0]
 [ 1  2  1  0  0  0]
 [ 1  3  3  1  0  0]
 [ 1  4  6  4  1  0]
 [ 1  5 10 10  5  1]]
>>> print(p.as_tri(sums=True))
[ 1  2  4  8 16 32]

diag walks through the array from a starting node by a fixed step. Row 4 of the triangle is an anti-diagonal of the rectangle; the main diagonal holds the central binomial coefficients.

>>> print(p.diag(loc=(4, 0), move=(-1, 1)))
[1 4 6 4 1]
>>> print(p.diag())
[  1   2   6  20  70 252]

The steeper diagonals sum to the Fibonacci numbers:

>>> f = ndplex(10)
>>> print([int(f.diag(loc=(k, 0), move=(-2, 1)).sum()) for k in range(10)])
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

Other arrays

ndplex(nrows, edges=(1, 1), arg_locs=None, func=sum, dtype=np.int64)

  • edges sets the front edges, as numbers or as sequences of length nrows. Their number sets the dimension. In 2-D, edges[0] fills column 0 and edges[1] fills row 0.
  • func generates each interior node from a list of argument values. The default is sum.
  • arg_locs gives where those arguments are, relative to the node. The default in 2-D is [[-1, 0], [0, -1]], the nodes above and to the left. A None coordinate means "on the edge".

Odd numbers along the top edge give the squares, the square pyramidal numbers, and so on down the rows:

>>> print(ndplex(5, edges=(1, [1, 3, 5, 7, 9])))
[[  1   3   5   7   9]
 [  1   4   9  16  25]
 [  1   5  14  30  55]
 [  1   6  20  50 105]
 [  1   7  27  77 182]]

Pascal's rule modulo 2 gives the Sierpinski pattern:

>>> print(ndplex(6, func=lambda x: sum(x) % 2))
[[1 1 1 1 1 1]
 [1 0 1 0 1 0]
 [1 1 0 0 1 1]
 [1 0 0 0 1 0]
 [1 1 1 1 0 0]
 [1 0 1 0 0 0]]

Adding the diagonal neighbour as a third argument gives the Delannoy numbers:

>>> print(ndplex(6, arg_locs=[[-1, 0], [0, -1], [-1, -1]]))
[[   1    1    1    1    1    1]
 [   1    3    5    7    9   11]
 [   1    5   13   25   41   61]
 [   1    7   25   63  129  231]
 [   1    9   41  129  321  681]
 [   1   11   61  231  681 1683]]

Higher dimensions

Three edges make Pascal's cube; as_tri shows it as a tetrahedron, layer by layer. Each layer holds the trinomial coefficients, and the layers sum to powers of 3.

>>> c = ndplex(4, edges=3)
>>> print(c.as_tri()[2])
[[1 2 1 0]
 [2 2 0 0]
 [1 0 0 0]
 [0 0 0 0]]
>>> print(c.as_tri(sums=True))
[ 1  3  9 27]

The same works in any number of dimensions: ndplex(5, edges=4) is a 4-D array, and its as_tri is a 4-simplex.

Large values

Node values grow quickly. With the default int64, the 2-D array is exact for nodes with i + j <= 66. If any node overflows, construction issues one RuntimeWarning naming the first node that did. For exact integers of any size, use dtype=object:

>>> print(ndplex(70, dtype=object)[69, 69])
23623985175715118288974865541854103729000

When only a residue is needed, reduce inside func instead, as in the Sierpinski example above.

Looking rows up in OEIS

oeis searches oeis.org for each row of an array and prints the best match. It sends one request per row, so please search a few rows at a time.

from ndplex import ndplex, oeis

oeis(ndplex(5))
oeis(ndplex(9).as_tri(), trim=True, size=5)   # rows of the triangle, zeros trimmed
matches = oeis(ndplex(5), quiet=True)        # a list of (A-number, name) or None

The output has one line per row, for example row 2: https://oeis.org/A000217 Triangular numbers: .... The names come from OEIS and can change. If oeis.org cannot be reached or refuses the request, the row's line says lookup failed (...). Each request identifies itself to oeis.org as ndplex/<version>.

Plotting

From 0.1.0, plotting is left to the user, so import ndplex needs only NumPy. The notebook's plot_ndplex and diag_as_hist are in ndplex_array.ipynb in the repository; an examples notebook that installs from PyPI is planned.

Changes from the notebook

ndplex began as the first code cell of ndplex_array.ipynb (2019–2024). The package keeps the notebook's results except where a change is documented. The changes are listed in the changelog, with migration notes in docs/. In brief: no import side effects, plotting left out, overflow reported, arg_locs outside the array read 0, diag ends where its moves leave the array, and as_tri layers are justified left in every dimension.

Background and credits

ndplex is the original work of Ted Teske (2019–2024). A general source for it is Thomas M. Green, The Simplex, Duplex and Pascal's Triangles: Relatives of Pascal's Triangle, with Excursions Into Hyperspace (CreateSpace, 2015; ISBN 9781514677094).

The packaging, tests and audit (2026) were developed with assistance from Claude (Anthropic). ATTRIBUTION.md sets out which work is whose, and the references.

Citing

Citation metadata are in CITATION.cff; GitHub's "Cite this repository" button reads it.

License

MIT. Copyright (c) 2019 Ted Teske.

Metadata

Release files for ndplex 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ndplex 0.1.0
File Size Uploaded Provenance Actions
ndplex-0.1.0.tar.gz 77.8 kB With provenance Details for ndplex-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ndplex 0.1.0
File Interpreter ABI Platform Actions
ndplex-0.1.0-py3-none-any.whl Python 3 none any Details for ndplex-0.1.0-py3-none-any.whl

Total release size: 91.7 kB

Release files / ndplex-0.1.0.tar.gz

Download URL ndplex-0.1.0.tar.gz
Size 77.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b9016870928f53b200202a3b70f1619fcab27526481ca80513bb5f5573793be3
BLAKE2b-256 checksum
How to use checksums
389d90cbd1448d4a878628953243d4156c430f1b0e8890c46762ff92dc69bff4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Release files / ndplex-0.1.0-py3-none-any.whl

Download URL ndplex-0.1.0-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d77fee268e60c55d0a36a47268fc86b80b20dfc9305881cabde1e398cee0352
BLAKE2b-256 checksum
How to use checksums
390cd9eb7b7c211f870275716f3150d4469b6d32f2a3902a3bc65a10b8512712
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

Security for ndplex 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ndplex-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page