(Z)
return Z
Perform an iteration of the system.
Perform an iteration of the system.
Perform an iteration of the system .
def iterate(Z):
    """Perform an iteration of the system."""
    # code from http://dana.loria.fr/doc/numpy-to-dana.html
    # find number of neighbours that each square has
    N = zeros(Z.shape)
    N[1:, 1:] += Z[:-1, :-1]
    N[1:, :-1] += Z[:-1, 1:]
    N[:-1, 1:] += Z[1:, :-1]
    N[:-1, :-1] += Z[1:, 1:]
    N[:-1, :] += Z[1:, :]
    N[1:, :] += Z[:-1, :]
    N[:, :-1] += Z[:, 1:]
    N[:, 1:] += Z[:, :-1]
    # a live cell is killed if it has fewer than 2 or more than 3 neighbours.
    part1 = ((Z == 1) & (N < 4) & (N > 1))
    # a new cell forms if a square has exactly three members
    part2 = ((Z == 0) & (N == 3))
    Z = (part1 | part2).astype(int)
    return Z
def iterate ( Z ) : # code from http://dana.loria.fr/doc/numpy-to-dana.html # find number of neighbours that each square has N = zeros ( Z . shape ) N [ 1 : , 1 : ] += Z [ : - 1 , : - 1 ] N [ 1 : , : - 1 ] += Z [ : - 1 , 1 : ] N [ : - 1 , 1 : ] += Z [ 1 : , : - 1 ] N [ : - 1 , : - 1 ] += Z [ 1 : , 1 : ] N [ : - 1 , : ] += Z [ 1 : , : ] N [ 1 : , : ] += Z [ : - 1 , : ] N [ : , : - 1 ] += Z [ : , 1 : ] N [ : , 1 : ] += Z [ : , : - 1 ] # a live cell is killed if it has fewer than 2 or more than 3 neighbours. part1 = ( ( Z == 1 ) & ( N < 4 ) & ( N > 1 ) ) # a new cell forms if a square has exactly three members part2 = ( ( Z == 0 ) & ( N == 3 ) ) Z = ( part1 | part2 ) . astype ( int ) return Z