更新时间:2021-11-27 18:02:07
z
或z_tbl[i+1]
是一个numpy数组.对于numpy数组,丰富的比较(==
,<=
,>=
,...)将返回另一个(布尔型)numpy数组.
Either z
or z_tbl[i+1]
is a numpy array. For numpy arrays, rich comparisons (==
, <=
, >=
, ...) return another (boolean) numpy array.
bool
会给您所看到的异常:
bool
on a numpy array will give you the exception that you are seeing:
>>> a = np.arange(10)
>>> a == 1
array([False, True, False, False, False, False, False, False, False, False], dtype=bool)
>>> bool(a == 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Numpy试图告诉您该怎么做:
Numpy is trying to tell you what to do:
>>> (a == 1).any() # at least one element is true?
True
>>> (a == 1).all() # all of the elements are true?
False