I'm trying to create an efficient implementation of a totalistic cellular automaton with three possible colors for each cell as in this image from Stephen Wolfram's book, A New Kind of Science:
If I have a numpy
array, can I create a new numpy
array by having a window of width 3 that slides over the original array, adds the three elements, and uses this sum as an index into a look-up table for the rule?
I was thinking I could use np.correlate
, but that wouldn't do the look-up in the rule array. Perhaps I could do that afterwards with a map.