pyCA.eca module
Elementary cellular automata.
An elementary cellular automaton (ECA) is the simplest interesting dynamical system there is: a periodic row of cells, each 0 or 1, each updating from its own value and its two neighbors’ values according to one of the 256 possible rules. Stephen Wolfram’s numbering names each rule by the byte whose bit n gives the output for the neighborhood whose (left, center, right) values read, as a binary number, n.
The ECA class mirrors the original MATLAB implementation: rule
and state are validated properties that can be reassigned at any time,
evolve advances one step, and play opens a live spacetime display.
- class pyCA.eca.ECA(rule, state=None, N=64, memory=None, rng=None)[source]
Bases:
objectA 1-dimensional elementary cellular automaton on a periodic lattice.
- Parameters:
rule (int) – Wolfram rule number, 0-255.
state (array_like of 0s and 1s, optional) – Initial state. If omitted, a random state of length N is drawn.
N (int, optional) – Lattice size used when state is omitted (default 64).
memory (int, optional) – Number of past states retained for spacetime and play. Defaults to max(min(3*N, 5000), 300), matching the MATLAB class.
rng (numpy.random.Generator, optional) – Random source; defaults to
numpy.random.default_rng().
- rule
The rule number. Reassigning it rebuilds the lookup table.
- Type:
int
- state
The current state. Reassigning it appends to the history.
- Type:
ndarray
- N
Lattice size.
- Type:
int
Examples
>>> from pyCA import ECA >>> ca = ECA(110, N=128) >>> ca.run(100) >>> ca.spacetime().shape (101, 128)