bobbyzamora
bobbyzamora

Reputation: 3

How to change an array to boolean values making the array output True/False

Make a new array where the elements are all Boolean values, representing whether or not the corresponding values in the solved board are odd. (That is to say, if a value is odd, the new array should have True in its corresponding location.)

Currently my code just outputs whether the values are true or false, but are not in the 9x9 array I need it to be in.

Array
solvedBoard = np.array([
                    [5, 3, 4, 6, 7, 8, 9, 1, 2],
                    [6, 7, 2, 1, 9, 5, 3, 4, 8],
                    [1, 9, 8, 3, 4, 2, 5, 6, 7],
                    [8, 5, 9, 7, 6, 1, 4, 2, 3],
                    [4, 2, 6, 8, 5, 3, 7, 9, 1],
                    [7, 1, 3, 9, 2, 4, 8, 5, 6],
                    [9, 6, 1, 5, 3, 7, 2, 8, 4],
                    [2, 8, 7, 4, 1, 9, 6, 3, 5],
                    [3, 4, 5, 2, 8, 6, 1, 7, 9]])


INPUT:
for item in np.nditer(solvedBoard1):
    if item%2 ==0:
    print("False")
else:
    print("True")

OUTPUT:
True
True
False
False
True
False
True etc...

Upvotes: 0

Views: 140

Answers (1)

zerecees
zerecees

Reputation: 699

Try a simple comparison answer = solvedBoard % 2 == 0

Upvotes: 1

Related Questions