【发布时间】:2015-06-03 16:18:56
【问题描述】:
我想知道如何在 Python 中执行以下 MATLAB 语句:
X(0.80 < X & X < 1) = 1;
这个声明说:Put 1 in the indices where the value of X is between 0.8 and 1。
我正在寻找 Python 列表的 NumPy 数组中的解决方案。
谢谢。
我试过了:
X[X > 0.8 and X < 1]
但它说:ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
【问题讨论】: