I need to find the row and column number of a specific index/item in a ndarray. I found nothing to do this simultaneously, so I tried to achieve this separately. In the shown code I only had at least an idea how to do this for the rows.
For this code the expected output should be 0. My idea was to iterate over the number of entries with for i in range(0, len(array)):. For i = 0 the wanted item is not found obviously. So if row != None: is not fulfilled so the loop should start over. For i = 1 the condition should be fulfilled and the loop should stop there and give the correct row number. But the output is ValueError: 2 is not in list. I found solution to avoid this error but not in the combination with a ndarray.
It feels like I just can't get behind the logic of the combination of the for loop and the if statement. I am seeking some enlightenment on how this works exactly.
array = [[0,1],
[2,3]]
row = None
item = 2
for i in range(0, len(array)):
row = array[i].index(item)
if row != None:
break
else:
continue
print(row)