-1

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:

totalistic cellular automaton

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.

Paul Reiners
  • 8,576
  • 33
  • 117
  • 202

1 Answers1

0
    a = self.array
    i = self.next
    window = [1, 1, 1]
    row = self.array[i - 1]
    correlated_row = np.correlate(row, window, mode="same")
    next_row = np.array([self.table[7 - total - 1] for total in correlated_row])
    a[i] = next_row
    self.next += 1
Paul Reiners
  • 8,576
  • 33
  • 117
  • 202