Home > Mobile >  I have no clue why this isnt working. Seems like a simple script but I keep getting 0 as my result w
I have no clue why this isnt working. Seems like a simple script but I keep getting 0 as my result w

Time:11-05

rows = len(myarray[0,:])
columns = len(myarray[:,1])
number_of_coordinates = 0
i=0
j=0
while i < rows:
    while j < columns:
        if int(myarray[i][j]) == 1:
            print("Found one!")
            number_of_coordinates  = 1
        j  = 1
    i  = 1
print(number_of_coordinates)

Should print out a high number I know I have many 1s in this array and the integers 2-10. The type of "int(myarray[i][j])" is "int" so I do not know what is wrong.

CodePudding user response:

You don't reinitialize j to zero,

rows = len(myarray[0,:])
columns = len(myarray[:,1])
number_of_coordinates = 0
i=0
j=0
while i < rows:
    
    while j < columns:
        if int(myarray[i][j]) == 1:
            print("Found one!")
            number_of_coordinates  = 1
        j  = 1
    i  = 1
    j = 0 # Look at it
print(number_of_coordinates)

Assuming you are using Python.

  • Related