I'm trying to get the index of elements in a row that is filled.
I tried to use numpy where() function, but it's only returning the index of non-zero elements.
import numpy as np
board = np.array([[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 2, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[2, 2, 2, 2],
[0, 0, 0, 0]])
for rows in board:
if set(rows) == {2}:
if len(set(rows)) <= 1:
print(np.where(board == rows))
My desired output is the following:
(array([9, 9, 9, 9], dtype=int32), array([0, 1, 2, 3], dtype=int32))
that is, row, col.
However, I'm getting this instead:
(array([2, 9, 9, 9, 9], dtype=int32), array([1, 0, 1, 2, 3], dtype=int32))
As stated above, it should only get the index of elements in a filled row. The board1 is not filled with 2's, yet it's being included.