1

I'm trying to run the following piece of code:

TN = np.sum((1 - predict) * (1 - actual))

where I have predicted, the variable that I cannot modify, which gets printed as follow:

[False False False False False False]

without any comma, so I guess it is not a list. Then, I have actual which is formatted as:

[False, False, False, False, False, False]

They have the same length, but when I run the command above I get the error:

TypeError: unsupported operand type(s) for -: 'int' and 'list'

How can I convert the variable actual so it can be compared to predicted?

2
  • How predicted is generated? can you know its type using type()? Commented Nov 15, 2021 at 7:40
  • 2
    This is a numpy operation and predicted seems to be a numpy array so if you convert actual to a numpy array you can do the operation: TN = np.sum((1 - predict) * (1 - np.array(actual))) Commented Nov 15, 2021 at 7:41

1 Answer 1

2

[False False False False False False] is a numpy array:

l = [False, False, False, False, False, False]

a = np.array(l)
print(a)

# Output
[False False False False False False]

I think you have to convert actual to numpy array.

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

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.