【发布时间】:2020-06-18 13:47:39
【问题描述】:
在 Matlab 中计算以下索引:
index = find(the(:) == lat & phi(:) == lon & ~isnan(dat(:)));
所有数组的大小相同。我正在尝试将此索引转换为在 python 中使用并添加另一个参数。这是我到目前为止所拥有的:
index = np.argwhere((the[:] == lat) & (phi[:] == lon) & (~np.isnan(dat[:])) & (start <= tim[:] <= stop))
这个想法是使用这个索引来查找数组中满足索引条件的所有值。当我尝试使用我制作的 Python 版本时,它返回错误:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我还没有让 a.all() 或 a.any() 工作。我需要使用这些吗?如果是这样,在这种情况下我该如何正确使用它们?
【问题讨论】:
-
请提供minimal reproducible example,以及完整的错误消息。顺便说一句,为什么所有
[:]?另外,我认为您不需要在这里使用argwhere()。
标签: python matlab indexing valueerror