Skip to content Skip to sidebar Skip to footer

Value Error: Truth Value Ambiguous

Following up from here: Conditional calculation in python I'm editing this line: out = log(sum(exp(a - a_max), axis=0)) from line 85 here: https://github.com/scipy/scipy/blob/v0.

Solution 1:

This expression

threshold if a - a_max < threshold else a - a_max

is the same as max(a - a_max, threshold). If a is a numpy array, then so is the expression a - a_max < threshold. You can't use a numpy array as the conditional expression in the Python if-else ternary operator, but you can compute element-wise the maximum using np.maximum. So you should be able to replace that expression with

np.maximum(a - a_max, threshold)

(np is numpy.)

Post a Comment for "Value Error: Truth Value Ambiguous"