def __init__(self, shape):
    self.db = Database()
    self.Cell = self._CellBaseClass._add_to_database(self.db)
    self.shape = shape
    self.grid = np.empty(self.shape, dtype=object)
    for x in range(self.shape[0]):
        for y in range(self.shape[1]):
            self.grid[(x, y)] = self.Cell(coordinates=(x, y))
    for x in range(self.shape[0]):
        for y in range(self.shape[1]):
            cell = self.grid[(x, y)]
            neighbors = []
            for x_offset in [(- 1), 0, 1]:
                for y_offset in [(- 1), 0, 1]:
                    nx = (x - x_offset)
                    ny = (y - y_offset)
                    if (nx < 0):
                        nx = 0
                    if (ny < 0):
                        ny = 0
                    if (nx >= self.shape[0]):
                        nx = (self.shape[0] - 1)
                    if (ny >= self.shape[1]):
                        ny = (self.shape[1] - 1)
                    neighbor = self.grid[(nx, ny)]
                    if (cell != neighbor):
                        neighbors.append(neighbor)
            cell.neighbors = neighbors
    self.db.get('Cell.neighbors').to_csr()
def __init__(self, shape):
    self.db = Database()
    self.Cell = self._CellBaseClass._add_to_database(self.db)
    self.shape = shape
    self.grid = np.empty(self.shape, dtype=object)
    for x in range(self.shape[0]):
        for y in range(self.shape[1]):
            self.grid[(x, y)] = self.Cell(coordinates=(x, y))
    for x in range(self.shape[0]):
        for y in range(self.shape[1]):
            cell = self.grid[(x, y)]
            neighbors = []
            for x_offset in [(- 1), 0, 1]:
                for y_offset in [(- 1), 0, 1]:
                    nx = (x - x_offset)
                    ny = (y - y_offset)
                    if (nx < 0):
                        nx = 0
                    if (ny < 0):
                        ny = 0
                    if (nx >= self.shape[0]):
                        nx = (self.shape[0] - 1)
                    if (ny >= self.shape[1]):
                        ny = (self.shape[1] - 1)
                    neighbor = self.grid[(nx, ny)]
                    if (cell != neighbor):
                        neighbors.append(neighbor)
            cell.neighbors = neighbors
    self.db.get('Cell.neighbors').to_csr()