0

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...
2
  • solvedBoard % 2 Commented Apr 13, 2020 at 3:28
  • What is the issue, exactly? Have you tried anything, done any research? Commented Apr 13, 2020 at 4:17

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a ton, also do you know how I would flip the Boolean value so instead of showing an odd number as false, it would show as true?
No problem! Just change the condition to solvedBoard %2 == 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.