chaos.py
442 B · python · 16 lines
1import numpy as np2import zlib3from typing import List45def chaos(grid: np.ndarray) -> float:6 raw = grid.tobytes()7 if len(raw) == 0:8 return 0.09 compressed = zlib.compress(raw)10 return len(compressed) / len(raw)1112def temporal_chaos(grids: List[np.ndarray]) -> float:13 if len(grids) < 2:14 return 0.015 diffs = [np.mean(grids[i] != grids[i - 1]) for i in range(1, len(grids))]16 return float(np.mean(diffs))