0

I am trying to modify the boolarr numpy array depending on the contents of the reducedMatrix array. It is supposed to change the boolean value of the boolarr to False if reducedMatrix is not a 0 or a -1.

reducedMatrix = np.load(reducedweightmatrix)

boolarr = np.ones(shape=(len(reducedMatrix),len(reducedMatrix)),dtype="bool")

for y,yelement in enumerate(reducedMatrix):
    for x,xelement in enumerate(yelement):
        if(xelement != -1 and xelement != 0):
            print(x)
            print(y)
            print("\n")
            boolarr[y,x] == False

print(reducedMatrix)
print(boolarr)

The log keeps on showing the following:

[[-1  5  5  0  0]
 [ 5 -1  0  0  0]
 [ 5  0 -1  0  5]
 [ 0  0  0 -1  0]
 [ 0  0  5  0 -1]]
[[ True  True  True  True  True]
 [ True  True  True  True  True]
 [ True  True  True  True  True]
 [ True  True  True  True  True]
 [ True  True  True  True  True]]

What am I doing wrong?

2 Answers 2

1

There is no need to edit boolarray elementwise when you can just create it in one vectorized line:

boolarray = (reducedMatrix == 0) | (reducedMatrix == -1)
# array([[ True, False, False,  True,  True],
#        [False,  True,  True,  True,  True],
#        [False,  True,  True,  True, False],
#        [ True,  True,  True,  True,  True],
#        [ True,  True, False,  True,  True]])
Sign up to request clarification or add additional context in comments.

Comments

1

You need to change

boolarr[y,x] == False

into

boolarr[y,x] = False

Comments

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.