← Back to context

Comment by bear8642

13 days ago

Would you prefer something like this numpy then?

  def life(x):
    y = np.array([np.roll(x, -1), np.roll(x, 0),np.roll(x, 1)])
    y = np.array([np.roll(y, -1, 1), np.roll(y, 0, 1),np.roll(y, 1, 1)])
    z = y.sum(1).sum(0)
    a = np.array([3 == z, 4==z])
    c = np.logical_and(np.array([np.ones(x.shape), x]), a)
    return np.logical_or(c[0], c[1])

Video of Scholes building up the life APL expression can be seen here: https://www.youtube.com/watch?v=a9xAKttWgP4