I would like to create a loop that shifts an array across, for this example, 3 steps, while adding a value of 1 during each shift. After 3 across shifts a new row is introduced with a starting value of 1, and the previous row stops accumulating. Then on the fifth across step, there should be a shift by one entire row, and the pattern of accumulation should repeat.
import numpy as nparr = np.zeros((20, 20), int)y, x = 15, 3n = 0 arr[y,x] = 1across = 5along = 3 # not used currentlyfor _ in np.arange(1, across+1): arr[y, x + _] += _*arr[y,x]+1 n += 1 if n == across - 2 : arr[y - 1, x+n] = arr[y, x] arr[y , x+n] = arr[y , x+n-1] if n == across - 1: arr[y-1,x+n]= arr[y , x] + 1 arr[y , x+n] = arr[y, x+n-1] if n == across: arr[y-1,x+n] = arr[y,x+n-1] +1 arr[y-2,x+n] = arr[y-1,x+n-1] arr[y,x+n] = 0 breakprint(arr)
This is not an efficient way of handling this problem, and would like some feedback on how to achieve this pattern; perhaps by updating the column positions/values after every across shift, and introducing a row shift in a better way?
The final array should look something like this after 14 shifts:
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 4 4 4 5 6 0 0] [0 0 0 0 0 0 0 0 2 2 2 3 4 7 8 9 9 9 0 0] [0 0 0 0 0 0 1 2 4 5 6 6 6 0 0 0 0 0 0 0] [0 0 0 1 2 3 3 3 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
I have tried to use a pandas dataFrame, .iloc, .at, and numpy.roll, but the effects were undesirable.
Now my solution only takes into account a specific row and column position, but I eventually need it to include arbitrary and multiple locations all producing a similar pattern.
Cheers!