I am having problems to be able to create a function that generates a square matrix (whatever it is, that is, if we enter an 8 in the function, it will create an 8x8) but that also generates a tunnel effect in it, assuming that the first outer layer is 0, the next interior 1, then again 0 and so on until you reach the center.
Once done, it should represent the graph, leaving something like this: 0 in white 1 in black:
At the moment I have this:
import numpy as np
import matplotlib.pyplot as plt
def mat_gen(x):
Z = np.zeros((x,x),dtype=int)
i=0
while i<=x:
Z[i:-i,i:-i] = 1
i=i+1
im=plt.imshow(Z)
plt.show()
return
mat_gen(12)
I'm stuck with the slicing to go to the third layer to put zeros on it... I only generate a frame of 0 and all 1 inside frankly I don't know how to approach it.
I managed to do the one with the chessboard, however this one... eludes me.
Thank you very much in advance!!