+3 votes
in Programming Languages by (56.5k 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

+3 votes
by (73.8k points)
selected by
 
Best answer

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)


...