Jupyter Notebook kernel dying in the middle of running code

452 Views Asked by At

I am trying to run this code in jupyter notebook and it runs halfway but then the kernel restarts and the code stops running. Does anyone know a fix for this?

import numpy as np
import matplotlib.pyplot as plt

def ant(nx, ny, nmoves):
    arr = np.ones((ny, nx))

    ix = nx//2
    iy = ny//2
    dx, dy = 1, 0
    for i in range(nmoves):
        if arr[iy,ix]:
            dx, dy = dy, -dx
        else:
            dx, dy = -dy, dx
        arr[iy,ix] = 1 - arr[iy,ix]
        ix, iy = ix+dx, iy+dy   
        
        %matplotlib osx 
        
        fig = plt.imshow(arr, cmap='Greys', interpolation='nearest')
        plt.axis('off')
        plt.show()
        plt.draw()
        plt.pause(0.00000000000000000000000000000000000000000001)

nx = 175
ny = 175
nmoves = 13000
ant(nx, ny, nmoves)

I tried reducing the particles to 5000 but still the kernel would restart and stop running the code. It's important for the particles to be a high number so that a repeating pattern in the output could be seen.

0

There are 0 best solutions below