1

So I have changed my previous code

if advice[i] == real_choice[i]:
        correct[i] = "CORRECT"
      else:
        correct[i] =  "INCORRECT"

to

correct = np.where( advice == real_choice, "CORRECT", "INCORRECT")

but now my code after this, that calculates the number of occurrences of the string "INCORRECT" in correct, no longer works:

num_incorrect = correct.str.count("INCORRECT").sum()

how can I do the above line in a way that is compatible with the new method?

0

2 Answers 2

2

np.where returns a numpy array, not a pandas series. So you want:

(correct=='INCORRECT').sum()
Sign up to request clarification or add additional context in comments.

1 Comment

That works, and it actually made me realize that it was indeed very simple and I was doing something else wrong. Thank you
0
# numpy array
(correct == "INCORRECT").sum()

dict(zip(*np.unique(correct, return_counts=True)))["INCORRECT"]

# list
list(correct).count("INCORRECT")

or

correct = np.where( advice[i] == real_choice[i], 1, 0)

incorrect_size = correct.size - correct.sum()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.