Whilst programming Cellular-Automaton (obviously not finished) I encountered issues with bounds. The goal for the result of this section is to have a value in the position (i,j) on a matrix depicting the average of a random value (and its direct neighbours) between 0 and 1.
How can I manage this without violating the boundary conditions/rules?
import numpy as np
def arr(size):
arraySize = size
Z = np.array([[np.random.uniform(0, 1) for x in range(arraySize)] for y in range(arraySize)])
return Z
def each_average(i,j,array):
x= (array[i])+(array[i+1])+(array[i-1])
y= x[j-1]+x[j]+x[j+1]
f= y/9
return f
def average(array):
i,j=0,0
average=[]
while j in range(len(array)):
while i in range(len(array)):
i=i+1
j=j+1
x = each_average(i,j,array)
average.append(x)
return average
Z=arr(4)
print average(Z)