human
1D Automata"
Please write code following the instructions in jupyter notebook style.
 Write me a code to 1D Automata and the other steps required?
assistant
#Here is code to 1D Automata and the other steps required.

class Automaton_1D:
    def __init__(self, n: int, states: int=2):
        """
        1D Automaton
        :param n: number of cells
        """
        self.n = n
        self.space = np.zeros(n, dtype=np.uint8)
        self.space[n//2] = 1
        #np.array([0,0,0,0,1,0,0,0,0,0])#np.random.choice(2, n)
    
    def update(self, rule: dict):
        """
        Update automaton state
        """
        tmp_space = self.space.copy()
        for i in range(self.n):
            neighbours = self.get_neighbours(i)
            tmp_space[i] = rule["".join([str(s) for s in neighbours])]
        self.space = tmp_space
        
    def get_neighbours(self, i: int):
        if i == 0:
            return np.insert(self.space[:2], 0, self.space[-1])
        elif i == self.n - 1:
            return np.insert(self.space[-2:], 2, self.space[0])
        else: 
            return self.space[max(0, i-1):i+2]

rule_0 = {'111': 1, '110': 1, '101': 1, '100': 1, '011': 1, '010': 1, '001': 1, '000': 0}
rule_sierpinski = {'111': 0, '110': 1, '101': 0, '100': 1, '011': 1, '010': 0, '001': 1, '000': 0}
rule_x = {'111': 0, '110': 0, '101': 0, '100': 1, '011': 1, '010': 1, '001': 1, '000': 0}