+3 votes
in Programming Languages by (19.0k points)

The following Python code is returning an error. What is wrong with the code? 

return 1.06 * min(np.sqrt(np.var(probs)), h) * len(probs)^(-1/5)

TypeError: ufunc 'bitwise_xor' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

1 Answer

+1 vote
by (29.6k points)

Are you trying to use len(probs) to the power of (-1/5)? If yes, the symbol "^" is not for the power operation in Python and hence you are getting the error. You need to use "**" for the power operation.

Replace the symbol "^" with "**" and it should fix the error.

return 1.06 * min(np.sqrt(np.var(probs)), h) * len(probs)**(-1/5)