在python逻辑运算时
a[0<a<1] = 2
或a[0<a & a<1] = 2
都会报错:ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
报错的原始是,[]的运算改变了数组维度,正确的适用方法是:
a[(a>0) & (a<1)] # 一定要有括号
或 a[np.logical_and(a>0, a<1)]
Refs:
https://stackoverflow.com/questions/34472814/use-a-any-or-a-all