【发布时间】:2014-10-28 23:50:10
【问题描述】:
从这里跟进:Conditional calculation in python
我正在编辑这一行:
out = log(sum(exp(a - a_max), axis=0))
从第 85 行开始:https://github.com/scipy/scipy/blob/v0.14.0/scipy/misc/common.py#L18
到这里:
out = log(sum(exp(threshold if a - a_max < threshold else a - a_max), axis = 0))
但我收到以下错误:
out = log(sum(exp(threshold if a - a_max < threshold else a - a_max), axis=0)) ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我可以从this 的回答中看到,可以使用 for 循环遍历每个值来修复错误...但是有没有办法将它合并到更快的代码中?我的数组有数以万计的元素。
【问题讨论】:
标签: python numpy conditional