I have a numpy array that looks like this:
The size can be changed by altering the 'row_num' and 'col_num' variables
[[0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0.]]
During the program, the array may look like this:
[[0. 0. 0. 0. 0. 0. 0.]
[2. 2. 2. 0. 2. 0. 0.]
[1. 1. 1. 0. 1. 0. 0.]
[2. 2. 2. 0. 2. 0. 0.]
[1. 1. 2. 0. 2. 0. 0.]
[2. 2. 0. 0. 0. 0. 0.]
[1. 1. 0. 0. 0. 1. 0.]]
I am trying to make a function to move number down the bottom, like gravity. So once the function has run, the array would look like:
[[0. 0. 0. 0. 0. 0. 0.]
[2. 2. 0. 0. 0. 0. 0.]
[1. 1. 0. 0. 0. 0. 0.]
[2. 2. 2. 0. 2. 0. 0.]
[1. 1. 1. 0. 1. 0. 0.]
[2. 2. 2. 0. 2. 0. 0.]
[1. 1. 2. 0. 2. 1. 0.]]
Currently, the code inside my function looks like:
for cols in range(col_num):
for rows in range(row_num-1):
if board[rows][cols] == 0 and board[rows+1][cols] == 1:
board[rows+1][cols] = 0
board[rows][cols] = 1
print('move down 1')
elif board[rows][cols] == 0 and board[rows+1][cols] == 2:
board[rows+1][cols] = 0
board[rows][cols] = 2
print('move down 2')
The print statements are working so the condition is being met, but it does not change the array